liveBook · Manning

Uninitialized memory

As explained in Modern C

An uninitialized object is a C object whose stored value has not been given a valid initial value before it is read or otherwise used.

An uninitialized object has not been given a valid initial value. In C, using one can cause incorrect results, crashes, data loss, or exposure of sensitive information. section 15.0

Reduce the risk by initializing objects before use:

  • Initialize every block-scope variable. section 15.0
  • Use calloc instead of malloc when suitable, and provide an initialization function for more complicated dynamically allocated structures. section 15.0

How Modern C covers it

How deep it goes
Lists initialization measures for block-scope variables and dynamically allocated structures.
Examples
Uses block-scope variables and dynamically allocated structures as cases requiring initialization.
What you can do after
Apply initialization to block-scope variables and choose suitable initialization methods for dynamically allocated objects.
How it connects
Links uninitialized-object risks with out-of-bounds access, ended object lifetimes, and integer overflow.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.