Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: deprecation note
Note
titleDeprecated

This guideline does not apply to code that need conform only to C23. Code that must conform to older versions of the C standard should still comply with this guideline.

The calloc() function takes two arguments: the number of elements to allocate and the storage size of those elements. Typically, calloc() implementations multiply these arguments to determine how much memory to allocate. Historically, some implementations failed to check whether out-of-bounds results silently wrapped [RUS-CERT Advisory 2002-08:02]. If the result of multiplying the number of elements to allocate and the storage size wraps, less memory is allocated than was requested. As a result, it is necessary to ensure that these arguments, when multiplied, do not wrap.

...