Skip to main content

Problem:

In Object COBOL Development Suite De-referencing a NULL pointer in C was treated as zero.  With Server Express it now returns the error:

Execution error : file '<file-name>'

error code: 114, pc=0, call=1, seg=0

114            Attempt to access item beyond bounds of memory (Signal 11)

Passing the NULL is not a problem. De-referencing a NULL pointer in the C PROGRAM is the problem.

The error occurs when you use "cob -x" to compile the C program, but does not occur when you just use straight "cc".  But dereferencing a NULL pointer is supposed to be an undefined operation in C.  

Resolution:

With Server Express we now put "-z" on the ld command line.  The -z was added to the HP-UX liblist because using it is widely considered best practice on that platform.

Dereferencing a null pointer in C causes Undefined Behavior, at which point the implementation is allowed to do anything.  (See ISO 9899:1999 for the technical definition of undefined behavior and null dereference.)  Misuse of null pointers is a significant flaw in poorly-written C code.  Most C experts prefer an implementation that traps such dereferences; that makes it easier to find those bugs.

The -Z option in the HP compiler is for compatibility with incorrect C programs that assume null pointers can be dereferenced for reading.

You can change your cob command to be -

              cob -x main.c ABC.c -Q "-Z"

Man page on HP/UX for linker option "-z":

           -z      Arrange for run-time dereferencing of null

                   pointers to produce a SIGSEGV signal.  (This

                   is the complement of the -Z option.)

Old KB# 2243