Learn C Programming

Lesson 7 of 10 · Pointers and Memory

Module 11 · Pointers and Memory

Bug Gallery: NULL, Dangling and the Wild Pointer

ProReading

Bob needs a function that makes a score and hands it back. An old book says returning the address of a local variable works for a while. Bob likes things that work for a while. On the Playground, the Compile output tab turns amber, the badge says Runtime error, and the Output tab says (no output).

Checking what this lesson needs for you…

What is inside Bug Gallery: NULL, Dangling and the Wild Pointer

  1. Bob's score: the address of a local that died
  2. The same bug behind an out-parameter
  3. A block's local dies at its closing brace
  4. NULL: a crash on the right line
  5. The wild pointer: an address nobody gave it
  6. Writing through a cast-away const
  7. Kenji's walk one box past the end
  8. The wrong type, and the missing ampersand
  9. What GCC 12 says, and what it cannot see
  10. AddressSanitizer and UBSan: catching what actually ran
  11. The pointer checklist