Change storage class 249
Initialize floating-point variables to IEEE NaN, pointer variables to an
invalid address, and integer variables to the maximum representable integer.
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.
Use the refined tactic when your compiler doesn't support an option for the
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.
Use this tactic at least once before the program is put into production, as
an additional testing strategy.
9 C+ +: Initializing all local pointer variables is cheap insurance.
Java requires the programmer to initialize local variables, so the
tactic is unnecessary.
Initializing all local pointer variables is cheap insurance.
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 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
9 Change heap variables to be located on the stack with the use of
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
This tactic can be useful for C++.
Java guarantees heap integrity, so this tactic is unnecessary.
This tactic can be useful for C.