H-Series Application Migration Guide (H06.03+)

General Programming Issues
H-Series Application Migration Guide429855-006
4-6
Examples of Programming Errors
Examples of Programming Errors
Here are several examples of programming errors that do not cause problems at
optimization level 0, but might cause problems at level 1 or 2.
Example 1. Overflowing a String Variable
Assume the existence of two procedures, CALLER and CALLEE. CALLER defines a
local variable L. CALLEE declares a string S of fixed size T. CALLER then calls
CALLEE. CALLEE overflows string S by writing more than T bytes to S. The net effect
is that local variable L in CALLER is overwritten by the write to S. This does not cause
a problem at levels 0 or 1 because the frame created in CALLEE is large enough to
handle the incorrect write to S. It does, however, cause a problem at level 2.
Example 2. Incorrect Use of setjmp() and longjmp()
Programs sometimes assume that local variable assignments between setjmp() and
longjmp() calls are preserved. However, that is not always true. The C standard states
that local variables that are not declared volatile, and have been changed between the
setjmp() call and the longjmp() call, have indeterminate values when control is passed
back to setjmp(). To ensure correct behavior, modified local variables must be declared
volatile. Because the values of the nonvolatile variables are indeterminate, an error
might occur only at different optimization levels, or possibly with different versions of
the compiler.
Example 3. Passing a 32-Bit Value in a 64-Bit Parameter
Assume the existence of two procedures, CALLER and CALLEE, and that CALLER
calls CALLEE. CALLEE is defined (by its prototype) to accept a 32-bit parameter. Now
suppose a different version of CALLEE, which accepts a 64-bit parameter, is linked into
the application. Unexpected behavior might occur, because the optimizer needs to
guarantee only that CALLER calls CALLEE with an outgoing register whose lower 32
bits are valid; the upper 32 bits can contain any value. However, if CALLEE expects a
64-bit parameter, the full 64 bits of the passed-in parameter are used, potentially
leading to incorrect results
Creating Unstructured Enscribe Files Might
Require Program Changes
On H-series systems, if an application creates an unstructured Enscribe file on a 512-
byte sector (such as on an ESS or JBOD disk drive), the Disk Process automatically
rounds up the extent size to the next 14-page boundary and adjusts the maximum
extents to approximate the total disk space requested. This rounding and adjustment is
required to support the checksum method, which includes a 4 KB checksum block for
each 28 KB of user data.