In this section:

Overview

This error is generated whenever an uninitialized pointer is dereferenced. Note: This error category will be disabled if full uninitialized memory checking is in effect (the default). In this case, errors are detected in the READ_UNINIT_MEM category instead.

CodeDescriptionEnabledReportedPlatform
READ_UNINIT_PTRReading from uninitialized pointer(tick)RuntimeWindows/Unix


Problem 

The following code attempts to use the value of the a pointer, even though it has never been initialized.

/*
 * File: readuptr.c
 */
main()
{
	int b, *a;

	b = *a;
	return (0);
}

Diagnosis at Runtime

[readuptr.c:8] **READ_UNINIT_PTR**
>>	 b = *a;
Reading from uninitialized pointer: a
Stack trace where the error occurred:
	main() readuptr.c, 8
  • Line 2: Source line at which the problem was detected.
  • Line 3: Description of the problem and the expression that is in error.
  • Line 5: Stack trace showing the function call sequence leading to the error. 

Repair

This problem is usually caused by omitting an assignment or allocation statement that would initialize a pointer. The code given can be corrected by including an assignment as shown below.

/*
* File: readuptr.c (Modified)
*/
main()
{
	int b, *a, c;
	c = 1;
	a = &c;
	b = *a;
	return (0);
}
  • No labels