Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this compliant solution, the multiplication of the two arguments num_elements and sizeof(long) is evaluated are checked 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.

Code Block
bgColor#ccccff
long *buffer;
size_t num_elements = calc_size();
errno = 0;
(void) multsize_tif (num_elements,  > SIZE_MAX/sizeof(long));
if (errno) {
  /* handle error condition */
}
buffer = calloc(num_elements, sizeof(long));
if (buffer == NULL) {
  /* handle error condition */
}

...