Uninitialized variable are often intermittent and can be particularly difficult to find using conventional means. This is because any alteration in the operation of the program may result in different behavior. It is not unusual for this type of bug to show up and then immediately disappear whenever you attempt to trace it.

Insure++ performs checking for uninitialized data in two sub-categories.

  • copyNormally, Insure++ doesn’t complain when you assign a variable using an uninitialized value, since many applications do this without error. In many cases the value is changed to something correct before being used, or may never be used at all.
  • read: Insure++ generates an error report whenever you use an uninitialized variable in a context which cannot be correct, such as an expression evaluation. 

 To clarify the difference between these categories consider the following code:

/*
 * File: readuni1.c
 */
 #include <stdio.h> 


 int main()
 {
	struct rectangle {
		 int width;
		int height;
	};

	struct rectangle box; 
	int area;
	box.width = 5;
	area = box.width*box.height; 
	printf("area = %d\n", area); 
	return (0);
}


In line 17 the value of box.height is used to calculate a value that is invalid. This is because its value was never assigned. Insure++ detects this error in the READ_UNINIT_MEM(read)category. This category is enabled by default, so a message will be displayed. If you changed line 17 to 17:

area = box.height; 

Insure++ would report errors of type READ_UNINIT_MEM(copy) for both lines 17 and 18, but only if you had unsuppressed this error category.



  • No labels