Versions Compared

Key

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

...

Code Block
bgColorccccff
void function(size_t len) {
   long *p;
   if (len > SIZE_MAX / sizeof(long)) {
      /* handle overflow */
   }
   p = malloc(len * sizeof(long));
   if (p == NULL) {
      /*   handle error */
   }
   /* ... */
   free(p);
}

Alternatively, the following idiom sizeof(*p) can be used to properly size the allocation:

...