BUG: Incorrect Code When Increment Pointer Based on a Pointer (122543)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Editions 1.0
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 5.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q122543 SYMPTOMS
Incorrect code is generated when an assignment is made in the same
statement where a pointer based on a pointer is incremented.
For example, executing the following code:
char buf[100];
void *pvbuf=buf;
unsigned int _based(pvbuf) *Test;
*(char _based(pvbuf) *)(((char *)Test)++) = '6'
in a Win32-based application causes an application error; executing the
same code in a 16-bit Windows-based application causes this error:
run-time error R6001
-null pointer assignment
CAUSE
The compiler generates an unnecessary sub command, as shown here:
mov bx,WORD PTR _Test
sub bx,WORD PTR _pvbuf ; Not needed
mov si,WORD PTR _pvbuf
mov BYTE PTR [bx][si],5
inc WORD PTR _Test
RESOLUTION
Split the statement into multiple lines. For example,
*(char _based(pvbuf) *)(((char *)Test)) = '5';
((char*)Test)++;
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 7/5/2005 |
---|
Keywords: | kbBug kbCodeGen KB122543 |
---|
|