Versions Compared

Key

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

...

Code Block
bgColor#FFCCCC
int buf[1024];
int *buf_ptr = buf;

while (havedata() && buf_ptr < buf + sizeof(buf))
{
    *buf_ptr++ = parseint(getdata());
}

Compliant Code

...

Solution

To correct this example, the size of buf can be directly added to buf and used as an upper bound. The integer literal is scaled to the size of an integer and the upper bound of buf is correctly checked.

...