9.18 Initialize local variables

9.18 Initialize local variables

9.18.1 Basic tactic

Use compiler options to initialize dynamically with unusual or invalid values those local (stack) variables that aren’t explicitly initialized.

9.18.2 Purpose

Reveal uninitialized variables that need to be initialized.

9.18.3 Questions answered

  • Which local variables are getting random values that are being used in computation?

  • Where is the first place that the random values are being used?

9.18.4 Potential problems

Computations may not fail with the values assigned.

9.18.5 Refined tactics

Initialize floating-point variables to IEEE NaN, pointer variables to an invalid address, and integer variables to the maximum representable integer.

9.18.6 Related tactics

  • Add code to assign values to all local variables.

  • Run the program on a different system, where 0 isn’t a valid address.

9.18.7 Choosing tactics

Use the refined tactic when your compiler doesn’t support an option for the basic tactic.

Use basic or related tactics when any of the following is true:

  • A bug occurs when the program is run standalone, but not when it’s run under a debugger.

  • A bug occurs when the program is run under one user account and environment, but not when it’s run under another.

Use this tactic at least once before the program is put into production, as an additional testing strategy.

9.18.8 Language specifics

  • C++: Initializing all local pointer variables is cheap insurance.

  • Java: Java requires the programmer to initialize local variables, so the tactic is unnecessary.

  • C: Initializing all local pointer variables is cheap insurance.

  • Fortran: Use initializers to ensure local variables have values.

Debugging by Thinking. A Multidisciplinary Approach
Debugging by Thinking: A Multidisciplinary Approach (HP Technologies)
ISBN: 1555583075
EAN: 2147483647
Year: 2002
Pages: 172

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net