Versions Compared

Key

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

...

The unsigned n may contain a value greater than INT_MAX. Assuming quiet wraparound on signed overflow, the loop executes n times because the comparison i < n is an unsigned comparison. Once i is incremented beyond INT_MAX, i takes on negative values starting with (INT_MIN). Consequently, the memory locations referenced by p[i] precede the memory referenced by p and a write - outside - array bounds occurs.

sizeof(size_t) > sizeof(int)

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

...

Bibliography

...

Section 7.19, "Common definitions <stddef.h>," and Section 7.22.3, "Memory management functions"

ISO/IEC TR 24731-1:2007

Bibliography

...