diff mbox series

[v2,01/10] hbitmap: assert that we don't create bitmap larger than INT64_MAX

Message ID 20191022125839.12633-2-vsementsov@virtuozzo.com
State New
Headers show
Series Further bitmaps improvements | expand

Commit Message

Vladimir Sementsov-Ogievskiy Oct. 22, 2019, 12:58 p.m. UTC
We have APIs which returns signed int64_t, to be able to return error.
Therefore we can't handle bitmaps with absolute size larger than
(INT64_MAX+1). Still, keep maximum to be INT64_MAX which is a bit
safer.

Note, that bitmaps are used to represent disk images, which can't
exceed INT64_MAX anyway.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 util/hbitmap.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/util/hbitmap.c b/util/hbitmap.c
index 66db87c6ff..0a0e0f2b89 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -708,6 +708,7 @@  HBitmap *hbitmap_alloc(uint64_t size, int granularity)
     HBitmap *hb = g_new0(struct HBitmap, 1);
     unsigned i;
 
+    assert(size <= INT64_MAX);
     hb->orig_size = size;
 
     assert(granularity >= 0 && granularity < 64);
@@ -738,6 +739,7 @@  void hbitmap_truncate(HBitmap *hb, uint64_t size)
     uint64_t num_elements = size;
     uint64_t old;
 
+    assert(size <= INT64_MAX);
     hb->orig_size = size;
 
     /* Size comes in as logical elements, adjust for granularity. */