...
Code Block | ||
---|---|---|
| ||
size_t num_elements = get_size();
long *buffer = calloc(num_elements, sizeof(long));
if (buffer == NULL) {
/* handle error condition */
}
/*...*/
free(buffer);
|
Compliant Solution
In this compliant solution, the multiplication of the two arguments num_elements
and sizeof(long)
is evaluated before the call to calloc()
to determine if an overflow will occur. The multsize_t()
function sets errno
to a non-zero value if the multiplication operation overflows.
...