Versions Compared

Key

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

...

Wiki Markup
See \[[INT01-A. Use rsize_t or size_t for all integer values representing the size of an object]\] for more information on  representing the size of objects.

Non-Compliant Code Example (

...

size calculation)

In this non-compliant code example, an array of long is allocated and assigned to p. However, sizeof(int) is used to size the allocated memory. If sizeof(long) is larger than sizeof(int) then an insufficient amount of memory is allocated.

...

This example also checks for unsigned integer overflow in compliance with INT32-C. Ensure that integer operations do not result in an overflow.

Compliant Solution (

...

size calculation)

To correct this the non-compliant code example, sizeof(long) is used to size the memory allocation.

...