In this section:

Overview

This error is generated whenever an uninitialized pointer is dereferenced.

CodeDescriptionEnabledReportedPlatform
WRITE_UNINIT_PTRWriting to an uninitialized pointer(tick)RuntimeWindows/Unix


Problem

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

/*
 * File: writuptr.c
 */
main()
{
	int *a;

	*a = 123;
	return (0);
}

Diagnosis at Runtime

[writuptr.c:8] **WRITE_UNINIT_PTR**
>>		*a = 123;
Writing to an uninitialized pointer: a
Stack trace where the error occurred:
			main() writuptr.c, 8
**Memory corrupted. Program may crash!!**
  • Line 2: Source line at which the problem was detected.
  • Line 3: Description of the problem and the expression that is in error.
  • Line 4: Stack trace showing the call sequence leading to the error.
  • Line 6: Informational message indicating that a serious error has occurred which may cause the program to crash.

Repair

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

/*
* File: writuptr.c (Modified)
*/
main()
{
	int *a, b;
	a = &b;
	*a = 123;
}
  • No labels