15 Program failure

 

This chapter covers

  • Wrongdoings leading to failure
  • Degradation of the program state
  • Unfortunate incidents
  • Anticipatory error checking
  • Cleanup

C programs can fail in very different ways—silently, sporadically, predictably, or with pomp and circumstance. Commonly, much emphasis is put on the things that may happen when a program fails, and attention is withdrawn from the questions of if a program fails and why. This is apparent with the term that is often (even falsely) applied to such situations: undefined behavior. This term even has an abbreviation in the jargon: UBC. As the term itself suggests, its focus is on the behavior of the program (or, better, the whole system) after an error occurred and not on the reasons that lead to the error. It’s a bit similar to trying to improve road safety by scaremongering drivers with fines or prison sentences, instead of promoting regular security checks of cars, requiring licenses, or educating drivers and passengers about the benefits of wearing a seat belt.

15.1 Wrongdoings

15.1.1 Arithmetic violations

15.1.2 Invalid conversions

15.1.3 Value violations

15.1.4 Type violations

15.1.5 Access violations

15.1.6 Value misinterpretation

15.1.7 Explicit invalidation

15.2 Program state degradation

15.2.1 Unbounded recursion

15.2.2 Storage exhaustion

15.2.3 Other scarce resources

15.3 Unfortunate incidents

15.3.1 Escalating state degradation

15.3.2 Collisions and race conditions

15.3.3 Inappropriate library calls and macro invocations

15.3.4 Deadlocks