]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Additional analogous assert in eratosthenese program.
authorNiels Möller <nisse@lysator.liu.se>
Fri, 13 Jul 2018 18:18:46 +0000 (20:18 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Fri, 13 Jul 2018 18:18:46 +0000 (20:18 +0200)
ChangeLog
examples/eratosthenes.c

index 1d318208af2aade2bb621bd71e4a4f693ff92f59..b6820bb77943026f1a80bfc58b4c52ea0b7b6f27 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@
        * examples/eratosthenes.c (vector_alloc): Add assert related to
        overflow in the size calculation. Fixes a corner case identified
        by static analysis.
+       (vector_init): Analogous assert.
 
 2018-07-12  Niels Möller  <nisse@lysator.liu.se>
 
index 35f84e1c00a916611fbe8777209e005e82d011fe..3857477878f3ff92d3a3dcda17ede2fa9d8071af 100644 (file)
@@ -111,8 +111,10 @@ vector_alloc(unsigned long size)
 static void
 vector_init(unsigned long *vector, unsigned long size)
 {
-  unsigned long end = (size + BITS_PER_LONG - 1) / BITS_PER_LONG;
-  unsigned long i;
+  unsigned long end, i;
+
+  assert (size <= ULONG_MAX - (BITS_PER_LONG - 1));
+  end = (size + BITS_PER_LONG - 1) / BITS_PER_LONG;
 
   for (i = 0; i < end; i++)
     vector[i] = ~0UL;