Page tree

Skip to end of metadata
Go to start of metadata

In this section:

Overview

This error is generated whenever an attempt is made to copy a pointer which points outside a valid range. It is not necessarily a serious problem, but may indicate faulty logic in the coding. Therefore, this error is suppressed by default.


CodeDescriptionEnabledReportedPlatform
COPY_BAD_RANGE

Attempt to copy out-of-range pointer

(error)RuntimeWindows/Unix


Problem

The following code, the pointer a in line 7 is initialized as an array of 10 chars. The next line then attempts to make pointer b point to an area that has not been allocated. The resulting pointer is not valid.

/*
 * File: copybad.cpp
 */
int main() {
	char *a, *b;

	a = new char [10];
	b = a + 20;
	return 0;
}

Diagnosis at Runtime

[copybad.cpp:8] **COPY_BAD_RANGE**
>> 					b = a + 20;
	Copying pointer which is out-of-range: a + 20

	Pointer : 		0x0007c124
	Actual block : 	0x0007c110 thru 0x0007c119 (10 bytes)
					a, allocated at:
						main() copybad.cpp, 7

Stack trace where the error occurred:
					main() copybad.cpp, 8
  • Line 1: Source line at which the problem was detected.
  • Line 3: Brief description of the problem. 
  • Line 5: Description of the pointer that is out of range.
  • Line 10: Stack trace showing the function call sequence leading to the error.

Repair

The simple way to avoid this problem is to not copy the invalid pointer. There may be an incorrect boundary case in your code causing the problem.

  • No labels