Insure++ Reference - FUNC_NULL
This error is generated when a function call is made via a
NULL function pointer.
This code attempts to call a function through a pointer that has
never been explicitly initialized. Since the pointer is a global variable,
it is initialized to zero by default, resulting in the attempt to call a
NULL pointer.
1: /*
2: * File: funcnull.c
3: */
4: void (*a)();
5:
6: main()
7: {
8: a();
9: return (0);
10: }
[funcnull.c:8] **FUNC_NULL**
1. >> a();
2. Function pointer is null: a
Stack trace where the error occurred:
3. main() funcnull.c, 8
4. **Memory corrupted. Program may crash!!**
- Source line at which the problem was detected.
- Description of the problem and the expression that is in error.
- Stack trace showing the function call sequence leading to the
error.
- Informational message indicating that a serious error has
occurred which may cause the program to crash.
The most common way to generate this problem is the one shown here, in
which the pointer never got explicitly initialized and is set to zero. This
case normally requires the addition of an assignment statement prior to
the call as shown below
/*
* File: funcnull.c (modified)
*/
void (*a)();
extern void myfunc();
main()
{
a = myfunc;
a();
return (0);
}
A second fairly common programming practice is to terminate arrays of
function pointers with NULL entries. Code that scans
a list looking for a particular function may end up calling the
NULL pointer if its search criterion fails. This
normally indicates that protective programming logic should be added to
prevent against this case.
FUNC_BAD
FUNC_UNINIT_PTR
|