]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: use 64-bits to shift order
authorJosh Durgin <josh.durgin@inktank.com>
Mon, 24 Sep 2012 21:25:26 +0000 (14:25 -0700)
committerSamuel Just <sam.just@inktank.com>
Tue, 25 Sep 2012 21:09:27 +0000 (14:09 -0700)
Order is never actually this high currently, but it be via librbd.

CID 716937: Overflowed return value (INTEGER_OVERFLOW)
At (3): Overflowed or truncated value (or a value computed from an
overflowed or truncated value) "offset" used as return value.

CID 717012: Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
At (1): Potentially overflowing expression "1 << obj_order" with type
"int" (32 bits, signed) is evaluated using 32-bit arithmetic before
being used in a context which expects an expression of type "uint64_t"
(64 bits, unsigned). To avoid overflow, cast the left operand to
"uint64_t" before performing the left shift.

CID 717011: Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
At (1): Potentially overflowing expression "1 << order" with type
"int" (32 bits, signed) is evaluated using 32-bit arithmetic before
being used in a context which expects an expression of type "uint64_t"
(64 bits, unsigned). To avoid overflow, cast the left operand to
"uint64_t" before performing the left shift.

CID 717013: Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
At (1): Potentially overflowing expression "1 << order" with type
"int" (32 bits, signed) is evaluated using 32-bit arithmetic before
being used in a context which expects an expression of type "uint64_t"
(64 bits, unsigned). To avoid overflow, cast the left operand to
"uint64_t" before performing the left shift.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
src/librbd/internal.cc

index 7b84bfcc35a8e2ccc54cae1df0be8122b3710691..a376da10f333198d166d8353643d54c290cbeacd 100644 (file)
@@ -111,7 +111,7 @@ namespace librbd {
     info.size = ictx->get_image_size(ictx->snap_id);
     ictx->snap_lock.Unlock();
     ictx->md_lock.Unlock();
-    info.obj_size = 1 << obj_order;
+    info.obj_size = 1ULL << obj_order;
     info.num_objs = howmany(info.size, get_block_size(obj_order));
     info.order = obj_order;
     memcpy(&info.block_name_prefix, ictx->object_prefix.c_str(),
@@ -140,26 +140,26 @@ namespace librbd {
     iss.ignore(object_prefix.length() + 1);
     uint64_t num, offset;
     iss >> std::hex >> num;
-    offset = num * (1 << order);
+    offset = num * (1ULL << order);
     return offset;
   }
 
   uint64_t get_max_block(uint64_t size, uint8_t obj_order)
   {
-    uint64_t block_size = 1 << obj_order;
+    uint64_t block_size = 1ULL << obj_order;
     uint64_t numseg = (size + block_size - 1) >> obj_order;
     return numseg;
   }
 
   uint64_t get_block_ofs(uint8_t order, uint64_t ofs)
   {
-    uint64_t block_size = 1 << order;
+    uint64_t block_size = 1ULL << order;
     return ofs & (block_size - 1);
   }
 
   uint64_t get_block_size(uint8_t order)
   {
-    return 1 << order;
+    return 1ULL << order;
   }
 
   uint64_t get_block_num(uint8_t order, uint64_t ofs)