lib/deltas: Squash Coverity warning for div-by-zero in delta show
authorColin Walters <walters@verbum.org>
Mon, 31 Jul 2017 16:27:31 +0000 (12:27 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 7 Aug 2017 16:10:08 +0000 (16:10 +0000)
If a delta happens to have zero objects, we could end up doing
a divide-by-zero when inferring endianness.  In practice,
a zero-object delta isn't possible to generate I think, but
let's make sure the code is defensive all the same.

Spotted by Coverity.

Coverity CID: 1452208

Closes: #1041
Approved by: pwithnall

src/libostree/ostree-repo-static-delta-core.c

index c8cefdefb0ed887ef23ee8cc003accecfe1c36aa..b8a2c590be7f9e5e776aa5734f8e2e42f1b6487a 100644 (file)
@@ -649,7 +649,7 @@ _ostree_delta_get_endianness (GVariant *superblock,
          * deltas, period.  Past the gigabyte scale you really want
          * bittorrent or something.
          */
-        if ((total_size / total_objects) > G_MAXUINT32)
+        if (total_objects > 0 && (total_size / total_objects) > G_MAXUINT32)
           {
             is_byteswapped = TRUE;
           }