From: Danny Al-Gaaf Date: Wed, 6 May 2015 13:45:01 +0000 (+0200) Subject: os/HashIndex.cc: add asserts to prevent BAD_SHIFT X-Git-Tag: v9.0.2~68^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0ae8fcadfb3c410bfb11a6c1b3e645d9e7ea0dce;p=ceph.git os/HashIndex.cc: add asserts to prevent BAD_SHIFT 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 --- diff --git a/src/os/HashIndex.cc b/src/os/HashIndex.cc index ead95b4024e..60d0082468e 100644 --- a/src/os/HashIndex.cc +++ b/src/os/HashIndex.cc @@ -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);