Search

ParaSoft

HOME
PRODUCTS
SUPPORT
ABOUT
WHAT'S NEW
EVENTS


Insure++

Quick facts

Add-on Modules:
   -INUSE
   -TCA

Comparisons

Technical Papers

Support & Manuals

FAQs

Recent Reviews

User Testimonials

Press Releases


Insure tool to debug c++





Insure++ Reference - FUNC_NULL



FUNC_NULL

Function pointer is NULL

This error is generated when a function call is made via a NULL function pointer.

Problem

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(); bug
	9:		return (0);
	10:	}

Diagnosis

	[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!!**
  1. Source line at which the problem was detected.
  2. Description of the problem and the expression that is in error.
  3. Stack trace showing the function call sequence leading to the error.
  4. Informational message indicating that a serious error has occurred which may cause the program to crash.

Repair

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
Tools to debug c++ and java
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft