]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/HashIndex.cc: add asserts to prevent BAD_SHIFT
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Wed, 6 May 2015 13:45:01 +0000 (15:45 +0200)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Mon, 1 Jun 2015 04:59:26 +0000 (06:59 +0200)
Fix for:

CID 1232599: Bad bit shift operation (BAD_SHIFT)
 negative_shift: In expression i << (4 - split_bits) % 4, shifting by
 a negative amount has undefined behavior. The shift amount,
 (4 - split_bits) % 4, is -1.

CID 1232600: Bad bit shift operation (BAD_SHIFT)
 negative_shift: In expression 1 << pg_num_bits - 1, shifting by a
 negative amount has undefined behavior. The shift amount,
 pg_num_bits - 1, is -1.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
src/os/HashIndex.cc

index ead95b4024e60beb489097c8df7eb751e4cdef10..60d0082468e80e71efe283eca3c93ffd9e6610be 100644 (file)
@@ -418,6 +418,7 @@ int HashIndex::pre_split_folder(uint32_t pg_num, uint64_t expected_num_objs)
   // the below logic is inspired by rados.h#ceph_stable_mod,
   // it basically determines how many sub-folders should we
   // create for splitting
+  assert(pg_num_bits > 0); // otherwise BAD_SHIFT
   if (((1 << (pg_num_bits - 1)) | ps) >= pg_num) {
     ++split_bits;
   }
@@ -430,6 +431,7 @@ int HashIndex::pre_split_folder(uint32_t pg_num, uint64_t expected_num_objs)
     leavies = leavies >> 4;
   }
   for (uint32_t i = 0; i < subs; ++i) {
+    assert(split_bits <= 4); // otherwise BAD_SHIFT
     int v = tmp_id | (i << ((4 - split_bits) % 4));
     paths.push_back(to_hex(v));
     ret = create_path(paths);