Learn C Programming

Lesson 6 of 9 · Arrays

Module 9 · Arrays

Bug Gallery: Out of Bounds and the Silent Write

ProReading

Bob needs ten boxes holding 1 to 10. He counts from 1, like every calendar he owns, and fills a[1] to a[10]. The Playground says Success and prints 0 1 2 3 4 5 6 7 8 9. Bob calls it a cosmetic issue.

Pro lesson

This one goes deeper

It is included with this track and with Learn Pro. Every question on the Skill Test can be answered from the free lessons, so this is depth and never a gate on the certificate.

What is inside Bug Gallery: Out of Bounds and the Silent Write

  1. One write past the end, and a Success badge
  2. When the compiler deletes the bad write
  3. A few boxes further, then far past the end
  4. Reading past the end: garbage that looks like an answer
  5. The off-by-one at the last index
  6. The array nobody filled
  7. The wrong count passed to a function
  8. Maria's bug: a countdown that cannot go below zero
  9. What GCC 12 says, and what it cannot see
  10. AddressSanitizer: a check on every box
  11. The names the security world uses: CWE-787, CWE-125, Heartbleed
  12. The array checklist