Commit 0b0c2314 authored by Niels Möller's avatar Niels Möller

Additional analogous assert in eratosthenese program.

parent dd279150
......@@ -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>
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment