]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
libceph: Avoiding divide by zero 18818/head
authoramitkuma <amitkuma@redhat.com>
Wed, 8 Nov 2017 18:32:39 +0000 (00:02 +0530)
committeramitkuma <amitkuma@redhat.com>
Mon, 20 Nov 2017 13:50:18 +0000 (19:20 +0530)
Fixes the coverity issue:
CID 1405270 (#1 of 1): Division or modulo by zero (DIVIDE_BY_ZERO)
2. divide_by_zero: In function call ll_get_stripe_osd,
division by expression l.stripe_count which may be zero has
undefined behavior.

Signed-off-by: Amit Kumar <amitkuma@redhat.com>
src/client/Client.cc

index 678184787a2426cef9593f2817579a5bc9c4c152..2f50317977202ae1395b1670c17e1866ebbc2803 100644 (file)
@@ -12292,9 +12292,12 @@ int Client::ll_get_stripe_osd(Inode *in, uint64_t blockno,
   uint32_t su = layout->stripe_unit;
   uint32_t stripe_count = layout->stripe_count;
   uint64_t stripes_per_object = object_size / su;
+  uint64_t stripeno = 0, stripepos = 0;
 
-  uint64_t stripeno = blockno / stripe_count;    // which horizontal stripe        (Y)
-  uint64_t stripepos = blockno % stripe_count;   // which object in the object set (X)
+  if(stripe_count) {
+      stripeno = blockno / stripe_count;    // which horizontal stripe        (Y)
+      stripepos = blockno % stripe_count;   // which object in the object set (X)
+  }
   uint64_t objectsetno = stripeno / stripes_per_object;       // which object set
   uint64_t objectno = objectsetno * stripe_count + stripepos;  // object id