Permalink
Browse files

Sanity check for the validness of a value instance in Item class

Change-Id: I6c08ceb5f0e83c02db2113159059e0534958ff1a
Reviewed-on: http://review.couchbase.org/12133
Reviewed-by: Michael Wiederhold <mike@couchbase.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
  • Loading branch information...
1 parent 09fb764 commit 7528e5bfe2aec223ef8db3e6cd906ec7b5fd90de @chiyoung chiyoung committed Jan 7, 2012
Showing with 14 additions and 6 deletions.
  1. +4 −0 item.cc
  2. +7 −3 item.hh
  3. +2 −2 objectregistry.cc
  4. +1 −1 queueditem.hh
View
@@ -19,6 +19,8 @@
Atomic<uint64_t> Item::casCounter(1);
bool Item::append(const Item &item) {
+ assert(value.get() != NULL);
+ assert(item.getValue().get() != NULL);
size_t newSize = value->length() + item.getValue()->length();
Blob *newData = Blob::New(newSize, '\0');
char *newValue = (char *) newData->getData();
@@ -35,6 +37,8 @@ bool Item::append(const Item &item) {
* @return true if success
*/
bool Item::prepend(const Item &item) {
+ assert(value.get() != NULL);
+ assert(item.getValue().get() != NULL);
size_t newSize = value->length() + item.getValue()->length();
Blob *newData = Blob::New(newSize, '\0');
char *newValue = (char *) newData->getData();
View
10 item.hh
@@ -180,7 +180,7 @@ public:
}
const char *getData() const {
- return value->getData();
+ return value.get() ? value->getData() : NULL;
}
const value_t &getValue() const {
@@ -204,7 +204,11 @@ public:
}
uint32_t getNBytes() const {
- return static_cast<uint32_t>(value->length());
+ return value.get() ? static_cast<uint32_t>(value->length()) : 0;
+ }
+
+ size_t getValMemSize() const {
+ return value.get() ? value->getSize() : 0;
}
time_t getExptime() const {
@@ -277,7 +281,7 @@ public:
}
size_t size() {
- return sizeof(Item) + key.size() + value->getSize();
+ return sizeof(Item) + key.size() + getValMemSize();
}
private:
View
@@ -90,7 +90,7 @@ void ObjectRegistry::onCreateItem(Item *pItem)
EventuallyPersistentEngine *engine = th->get();
if (verifyEngine(engine)) {
EPStats &stats = engine->getEpStats();
- stats.memOverhead.incr(pItem->size() - pItem->getValue()->getSize());
+ stats.memOverhead.incr(pItem->size() - pItem->getValMemSize());
assert(stats.memOverhead.get() < GIGANTOR);
}
}
@@ -100,7 +100,7 @@ void ObjectRegistry::onDeleteItem(Item *pItem)
EventuallyPersistentEngine *engine = th->get();
if (verifyEngine(engine)) {
EPStats &stats = engine->getEpStats();
- stats.memOverhead.decr(pItem->size() - pItem->getValue()->getSize());
+ stats.memOverhead.decr(pItem->size() - pItem->getValMemSize());
assert(stats.memOverhead.get() < GIGANTOR);
}
}
View
@@ -78,7 +78,7 @@ public:
}
size_t size() {
- return sizeof(QueuedItem) + getKey().size() + getValue()->getSize();
+ return sizeof(QueuedItem) + getKey().size() + item.getValMemSize();
}
private:

0 comments on commit 7528e5b

Please sign in to comment.