Programs might contain intentional truncation at runtime, such as when obtaining a hash value from a pointer or integer. To avoid runtime failures on these truncations, you can explicitly mask off the value:

ch = (int_val & 0xff);

Note that the +check=all option does not imply +check=truncate. To enable +check=truncate, you must explicitly specify it.

+check=truncate:explicit

This option turns on runtime checks for truncation on explicit user casts of integral values, such as (char)int_val.

+check=truncate:implicit

This option turns on runtime checks for truncation on compiler-generated implicit type conversions, such as ch = int_val.

+check=truncate

This option turns on runtime checks for both explicit cast and implicit conversion truncation.

+check=uninit

This option checks for a use of a stack variable before it is defined. If such a use is detected, an error message is emitted and the program is aborted. The check is done by adding an internal flag variable to track the definition and use of user variables.

If the +check=bounds:pointer is on, +check=uninit will check pointer access for uninitialized memory read (UMR). To enable checking, the runtime system will initialize the heap objects and stack variables with a special pattern. If the pointer accesses an area containing the specified pattern for the specified length, then it assumes the read is UMR. To minimize UMR false positives, the user may change the special pattern and number of bytes to check by using RTC_UMR environment variable:

RTC_UMR=[INIT=0xnn][:CHECK_SIZE=sz]

where:

INIT specifies the char type value used to initialize heap/local objects. The default pattern is 0xDE.

CHECK_SIZE specifies the minimum number of bytes used to check for UMR. The default number is

2.

Also see the +Oinitcheck option to enable compile time warnings for variables that may be used before they are set.

+check=malloc

This option enables memory leak and heap corruption checks at runtime. It will cause the user program to abort for writes beyond boundaries of heap objects, free or realloc calls for a pointer that is not a valid heap object, and out-of-memory conditions. Memory leak information is captured and written to a log file when the program exits. The name of the logfile is printed before program termination.

The +check=malloc option works by intercepting all heap allocation and deallocation calls. This is done by the use of a debug malloc library, librtc.so. The option works for programs that use the system malloc or for user-provided malloc routines in a shared library. The librtc.so library is also used by the HP WDB debugger to provide heap memory checking features in the debugger. Please refer to the HP WDB debugger documentation for more information about heap

13

Page 13
Image 13
HP C/aC++ for PA-RISC Software manual Ch = intval & 0xff