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

Last reviewed: August 8, 1997
Article ID: 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 <windows.h>

   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          : CLIss kb16bitonly
Version           : 1.5 1.51 1.52 1.52b 1.52c
Platform          : WINDOWS
Issue type        : kbbug


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.