Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 326529

Summary: when assigning a value to pointee, pointer changes as well
Product: [Tools] CDT Reporter: MIke <mikesongming>
Component: cdt-buildAssignee: cdt-build-inbox <cdt-build-inbox>
Status: RESOLVED INVALID QA Contact: Andrew Gvozdev <angvoz.dev>
Severity: normal    
Priority: P3    
Version: 8.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description MIke CLA 2010-09-29 09:04:51 EDT
Build Identifier: 20100617-1415

When practicing dynamic allocation, I wrote some code as follows: 
	int *p, *q;
	int arr[] = {1,2,3,4,5};
	p=arr;
	q=p+5;
	*q=6;

After the last sentence was exercised, the reference of "p" also changed to "0x06". It seems that when I gave "*q" an assignment, the reference of "p" was assigned with 6 too, while it should not change.

Reproducible: Always

Steps to Reproduce:
1. reference assignment of a pointer-to-integer "p" with an array "arr"
2. assign "p+5" to another pointer-to-integer "q"
3. assign an integer, say 6, to "*q"

Through debug, you can see that value of "p" changes to "0x06" as well
Comment 1 Andrew Gvozdev CLA 2010-09-29 11:38:34 EDT
The bug is in your code, not in CDT. p+5 refers outside of the array. Apparently that particular compiler allocates p itself at that memory location, i.e. at the point of initialization.