From: Niels Möller Date: Fri, 13 Jul 2018 18:18:46 +0000 (+0200) Subject: Additional analogous assert in eratosthenese program. X-Git-Tag: nettle_3.5rc1~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b0c23141d82a04ff9cc4815524c6e4a55434039;p=thirdparty%2Fnettle.git Additional analogous assert in eratosthenese program. --- diff --git a/ChangeLog b/ChangeLog index 1d318208..b6820bb7 100644 --- 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 diff --git a/examples/eratosthenes.c b/examples/eratosthenes.c index 35f84e1c..38574778 100644 --- a/examples/eratosthenes.c +++ b/examples/eratosthenes.c @@ -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;