Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Runtime Failures

โญ beginnerโณ 14 min read๐Ÿ“ Lesson 69 of 225

Segfaults, wrong outputs, and hangs: the three failure families and their usual suspects.

Family 1: the crash (segfault)

The process dies with Segmentation fault. Usual suspects, in order:

  1. NULL or uninitialized pointer dereference
  2. out-of-bounds array index
  3. use-after-free / dangling pointer
  4. writing through a bad pointer in a string function

A segfault tells you WHERE it died (the stack trace) but not WHY โ€” the bad address was usually produced much earlier.

Family 2: wrong output, no crash

The sneakiest. Causes: off-by-one loop bounds, wrong comparison operator, accumulating into the wrong variable, format-specifier mismatch, integer division where you meant floating division. The defense is tests with known answers โ€” exactly what this course's challenges run against your code.

Family 3: the hang

An infinite loop: the counter never moves toward the bound, or the termination condition can never become false. Check that something in the loop body changes every iteration.

The debugging loop

  1. reproduce โ€” find the smallest input that fails
  2. predict โ€” say out loud what SHOULD happen
  3. instrument โ€” print the values at each step (printf is the oldest debugger and still a great one)
  4. narrow โ€” binary-search the pipeline: is the input already wrong, or the processing?
  5. fix the cause, not the symptom โ€” a swallowed crash returns as a worse bug