Microsoft KB Archive/149785

{|
 * width="100%"|

BUG: GP Fault When You Access Struct Member Using Huge Pointer

 * }

Q149785

--- The information in this article applies to: - The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft Visual C++ for Windows, versions 1.5, 1.51, 1.52, 1.52b, 1.52c --- SYMPTOMS ======== When you use a huge pointer to a structure to reference a member variable whose offset is greater than 32K from the beginning of the structure, a general protection (GP) fault occurs when optimizations are disabled. CAUSE ===== The member offset is improperly sign-extended and added to the base address of the structure giving an invalid address. RESOLUTION ========== There are two workarounds: - Turn on an optimization by using /O1, /O2, or /Oa. -or- - Change the order of the members of the structure so that none of the members is more than 32K from the base of the structure. STATUS ====== Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available. MORE INFORMATION ================ Sample Code --- /* Compile options needed: /Od, /Mq (QuickWin App) */ #include typedef struct { char table[32768]; int nbtran; } MyStruct; MyStruct __huge *lptr; void main(void) { HANDLE hbuff = GlobalAlloc(GMEM_MOVEABLE,60000); lptr = (MyStruct __huge *) GlobalLock(hbuff); lptr->nbtran=10; // *** GPF here! *** }

Keywords : kb16bitonly kbCompiler

Issue type : kbbug

Technology : kbVCsearch kbAudDeveloper kbCVCComp