X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iotcloud.git;a=blobdiff_plain;f=version2%2Fsrc%2FC%2FSlotBuffer.cc;h=aa217ac17dda116f1ca2c48c3d498a93d182ae9d;hp=de4bbe0bc64a43f14851d46b2eb401dbeacbc409;hb=b2bc9b5c707bd7d932d60cd4e8c1cb580b36b5b4;hpb=2d567b75be4055f6a40ffe1cedb5cdc9be262d86 diff --git a/version2/src/C/SlotBuffer.cc b/version2/src/C/SlotBuffer.cc index de4bbe0..aa217ac 100644 --- a/version2/src/C/SlotBuffer.cc +++ b/version2/src/C/SlotBuffer.cc @@ -13,6 +13,10 @@ SlotBuffer::SlotBuffer() : oldestseqn(0) { } +SlotBuffer::~SlotBuffer() { + delete array; +} + int SlotBuffer::size() { if (head >= tail) return head - tail; @@ -24,7 +28,7 @@ int SlotBuffer::capacity() { } void SlotBuffer::resize(int newsize) { - if (newsize == (array->length() - 1)) + if ((uint32_t)newsize == (array->length() - 1)) return; Array *newarray = new Array(newsize + 1); @@ -32,7 +36,7 @@ void SlotBuffer::resize(int newsize) { int index = tail; for (int i = 0; i < currsize; i++) { newarray->set(i, array->get(index)); - if ((++index) == array->length()) + if (((uint32_t)++ index) == array->length()) index = 0; } array = newarray; @@ -42,13 +46,13 @@ void SlotBuffer::resize(int newsize) { void SlotBuffer::incrementHead() { head++; - if (head >= array->length()) + if (((uint32_t)head) >= array->length()) head = 0; } void SlotBuffer::incrementTail() { tail++; - if (tail >= array->length()) + if (((uint32_t)tail) >= array->length()) tail = 0; } @@ -56,7 +60,6 @@ void SlotBuffer::putSlot(Slot *s) { int64_t checkNum = (getNewestSeqNum() + 1); if (checkNum != s->getSequenceNumber()) { - // We have a gap so expunge all our slots oldestseqn = s->getSequenceNumber(); tail = 0; head = 1; @@ -82,21 +85,20 @@ Slot *SlotBuffer::getSlot(int64_t seqnum) { int32_t index = diff + tail; if (index < 0) { - // Really old message so we dont have it anymore return NULL; } - if (index >= array->length()) { + if (((uint32_t)index) >= array->length()) { if (head >= tail) { return NULL; } - index -= array->length(); + index -= (int32_t) array->length(); } - if (index >= array->length()) { - + if (((uint32_t)index) >= array->length()) { return NULL; } + if (head >= tail && index >= head) { return NULL; }