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 - COPY_BAD_RANGE



COPY_BAD_RANGE

Copying pointer which is out-of-range

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.

Problem

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


	1: 	/*
	2:	 * File: copybad.C
	3:	 */
	4:	int main() {
	5:		char *a, *b;
	6:
	7:		a = new char [10];
	8:		b = a + 20; bug
	9:		return 0;
	10:	}

Diagnosis (at runtime)


1.	[copybad.C:8] **COPY_BAD_RANGE**
	>> 		b = a + 20;
	
2.		Copying pointer which is out-of-range: a + 20
	
3.		Pointer		: 0x0007c124
		Actual block	: 0x0007c110 thru 0x0007c119 (10 bytes)
			   a, allocated at:
					main()	copybad.C, 7
	
4.		Stack trace where the error occurred:
					main()	copybad.C, 8

  1. Source line at which the problem was detected.
  2. Brief description of the problem.
  3. Description of the pointer which is out-of-range.
  4. 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.


<- BAD_PARM -> COPY_DANGLING
Tools to debug c++ and java
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft