FIX: GP Fault When For Loop Used with Unsigned Char IndexLast reviewed: September 18, 1997Article ID: Q128897 |
2.00 2.10
WINDOWS NT
kbtool kbbuglist kbfixlist
The information in this article applies to:
SYMPTOMSIf you access a structure member when using an unsigned char index in a For loop, a general protection (GP) fault occurs.
CAUSEWhen the compiler is optimizing for speed, only the low byte of the register where the index is stored is zeroed. Later on, the full extended register is used in calculating the offset of the structure member. Because the rest of the register is never zeroed, the offset used is invalid.
RESOLUTIONUse either one of the following workarounds:
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Microsoft Visual C++, 32-bit Edition, version 4.0.
MORE INFORMATIONThe sample code below can be used to demonstrate the problem. Due to the complexity of the optimization algorithm, some structures may work while others fail. However until this bug is fixed, it should be considered unsafe to use unsigned char indexing in a For loop with speed optimization.
Sample Code to Reproduce Problem
/* Compile options needed: any speed optimizations */struct TEST { char filler[37]; int x;} xyz[2];
void main(){ unsigned char i = 1; for(i=0; i<2; i++) { xyz[i].x = -1; }}
|
Additional reference words: 2.00 2.10 VCx86 GPF
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |