From: xie xingguo Date: Wed, 20 Jul 2016 05:48:07 +0000 (+0800) Subject: kv/MemDB: assert to confirm that we don't access violation or underflow X-Git-Tag: ses5-milestone5~296^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a16ba7d0ae1bb6ac1009edc7f6e06a2d92b965a0;p=ceph.git kv/MemDB: assert to confirm that we don't access violation or underflow Signed-off-by: xie xingguo --- diff --git a/src/kv/MemDB.cc b/src/kv/MemDB.cc index ed3483ef999..7b0d5cbac28 100644 --- a/src/kv/MemDB.cc +++ b/src/kv/MemDB.cc @@ -36,6 +36,7 @@ static void split_key(const string& raw_key, string *prefix, string *key) { size_t pos = raw_key.find(KEY_DELIM, 0); + assert(pos != std::string::npos); *prefix = raw_key.substr(0, pos); *key = raw_key.substr(pos + 1, raw_key.length()); } @@ -258,6 +259,7 @@ int MemDB::_setkey(ms_op_t &op) /* * delete and free existing key. */ + assert(m_total_bytes >= bl_old.length()); m_total_bytes -= bl_old.length(); m_btree.erase(key); } @@ -274,6 +276,7 @@ int MemDB::_rmkey(ms_op_t &op) bufferlist bl_old; if (_get(op.first.first, op.first.second, &bl_old)) { + assert(m_total_bytes >= bl_old.length()); m_total_bytes -= bl_old.length(); } /* @@ -331,6 +334,7 @@ int MemDB::_merge(ms_op_t &op) bl_old.clear(); } + assert((int64_t)m_total_bytes + bytes_adjusted >= 0); m_total_bytes += bytes_adjusted; return 0; }