From 74b85e7cdf6b897a649b3462150a60498a6758ed Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Mon, 24 Sep 2012 14:25:26 -0700 Subject: [PATCH] librbd: use 64-bits to shift order 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 --- src/librbd/internal.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 7b84bfcc35a8e..a376da10f3331 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -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) -- 2.39.5