...
The following noncompliant code example defines A
to be a variable length array type and then uses the sizeof
operator to compute its size at runtime. When the function is called with an argument greater than SIZE_MAX / (N1 * sizeof (int)
), the runtime sizeof
expression may wrap around, yielding a result that is smaller than the mathematical product N1 * n2 * sizeof (int)
. The call to malloc()
, when successful, will then allocate storage for fewer than n2
elements of the array, causing one or more of the final memset()
calls in the for
loop to write past the end of that storage.
...