9.19
Change storage class 249
9.18.5
9.18.6
9.18.7
Refined tactics
Initialize floating-point variables to IEEE NaN, pointer variables to an
invalid address, and integer variables to the maximum representable integer.
Related tactics
9 Add code to assign values to all local variables.
9 Run the program on a different system, where 0 isn't a valid address.
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:
9 A bug occurs when the program is run standalone, but not when it's
run under a debugger.
9 A bug occurs when the program is run under one user account and
environment, but not when it's run under another.
9.18.8
Use this tactic at least once before the program is put into production, as
an additional testing strategy.
Language specifics
9 C+ +: Initializing all local pointer variables is cheap insurance.
9 Java:
Java requires the programmer to initialize local variables, so the
tactic is unnecessary.
9 C:
Initializing all local pointer variables is cheap insurance.
9 Fortran:
Use initializers to ensure local variables have values.
9.19 Change storage class
9.1 9. I Basic tactic
Change local variable references to be global variables.
I Chapter 9
250 9.19 Change storage class
9.1 9.2 Purpose
Determine whether stack corruption is causing the problem.
9.19.3
Questions answered
9 Which stack variables were having their values overwritten?
9 Was the stack frame itself being overwritten?
9.19.4 Potential problems
This approach won't work with algorithms that really need a stack.
9.19.5 Refined tactics
Put preprocessor conditional compile directives around all stack variable
declarations so you can switch between locals and globals.
9.19.6 Related tactics
9 Change local variable references to be heap variables pointed to by
global variables.
9 Change heap variables to be located on the stack with the use of
alloca (nonportable).
9 Put arrays of pad values between each true variable on the stack.
9.1 9.7 Choosing tactics
Use the basic or refined tactic when both of the following are true:
9 Symptoms change radically between runs.
9 Local variables are being overwritten, but their address isn't being
taken.
9.19.8
Language specifics
9 C++:
This tactic can be useful for C++.
9 Java:
Java guarantees heap integrity, so this tactic is unnecessary.
9 C:
This tactic can be useful for C.

Get Debugging by Thinking now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.