You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

The ISO/IEC 9899 specifies that malloc, calloc, and realloc take a variable of type size_t as a size parameter. If an argument that is not of type size_t is supplied as the size parameter, that argument is converted to a size_t.

If a size parameter is stored in variables of type size_t, but operated on in such a way that it is temporarily stored in a variable that is not of type size_t, then the original value of the size may be truncated. When this value is passed to malloc, calloc, or realloc, a block of memory with an unexpected size may be allocated.

To prevent this error, size parameters should not be operated on in a way that they are stored in different data types

  • No labels