Game Development Reference
In-Depth Information
3. ShowDuration(TRUE);
No duration value is provided. If it defaults to 0 as a result of a local variable being
declared within the ShowDuration routine, then no value will be displayed.
4. ShowDuration(TRUE, g_vanishDuration[level] | 0x8000);
Here's a case where the code is unnecessarily fancy and gets into trouble. An assumption
was made that the high-order bit in the duration value acts as a flag that must be set
to cause the value to be displayed. This could be left over from an older implementa-
tion of this function or a mistake made by trying to reuse code from some other function.
Instead of the intended result, this changes the sign bit of the duration value and
negates it. Since the value used inside of ShowDuration will be less than zero, it will not
be displayed.
5. ShowDuration(TRUE, g_vanishDuration[level] ^ TRUE);
More imaginary complexity here has led to an Exclusive OR operation performed on
the duration value. Once again, this is a possible attempt to use some particular bit in
the duration value as an indicator for whether or not to display the value. In the case
where TRUE is 0xFFFF , this will invert all of the bits in the duration, causing it to be
passed in as a negative number, thus altering its value and preventing it from being
displayed.
6. ShowDuration(FALSE, g_vanishDuration[level+1]);
This can happen when an incorrect assumption is made that the level value needs to
be incremented to start with array element 1 for the first duration. When level is 3,
this could result in a 0 duration, since g_vanishDuration[4] is not defined. That would
prevent the value from being displayed.
7. ShowDuration(FALSE, g_vanishDuration[level-1]);
Here the wrong assumption is made that the level value needs to be decremented to
start with array element 0 for the first duration. When level is 1, this could return a 0
value and prevent the value from being displayed.
Okay, some of these examples are way out there, but pay attention to the variety of
ways every single parameter of every single function call can be a ticking time bomb.
One wrong move can cause a subtle, undetected, or severe Interface defect.
Search WWH ::




Custom Search