| Summary: | when assigning a value to pointee, pointer changes as well | ||
|---|---|---|---|
| Product: | [Tools] CDT | Reporter: | MIke <mikesongming> |
| Component: | cdt-build | Assignee: | 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: | |||
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. |
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