In this section:
A particularly difficult problem to track with conventional methods is that of incorrect return code from system functions. Insure++ is equipped with interface definitions for system libraries that enable it to check for errors when functions are called. Normally, these messages are suppressed, since applications often include their own handling for system calls that return errors. In some cases, however, it may be useful to enable these messages to track down totally unexpected behavior.
|
The following code shows an application that will run out of memory.
/* * File: retfail.c */ #include <stdio.h> int main() { FILE *f; f = fopen("/no/such/file or directory", "r"); /* expect failure */ return (0); } |
Normally, the code will run without displaying any messages. If RETURN_FAILURE
messages are enabled, however, the following display will result.
[retfail.c:9] **RETURN_FAILURE** >> f = fopen("/no/such/file or directory","r"); /* expect failure */ Function returned an error: fopen("/no/such/file or directory","r") failed. Stack trace where the error occurred: fopen() (interface) main() retfail.c, 9 |
These messages are normally suppressed but can be enabled by unsuppressing RETURN_FAILURE
.