Versions Compared


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


In this example, a dynamic array of integers is allocated to store s elements. However, if s is zero, the call to malloc(s) will return a reference to a block of memory of size 0. When data is copied to this location, a heap-buffer overflow will occur.

Code Block
list = malloc(sizeof(int) *)malloc( s);
if (list == NULL) {
  /* Handle Allocation Error */
/* Continue Processing list */