[wx-dev] #9726: misalignment on x64 causing C4328 warning and possibly program exception

wxTrac noreply at wxsite.net
Mon Jul 14 01:51:23 PDT 2008


Ticket URL: <http://trac.wxwidgets.org/ticket/9726>

#9726: misalignment on x64 causing C4328 warning and possibly program exception
---------------------------+------------------------------------------------
 Reporter:  hajokirchhoff  |       Owner:         
     Type:  defect         |      Status:  new    
 Priority:  high           |   Milestone:         
Component:  wxMSW          |     Version:  2.9-svn
 Keywords:  x64 alignment  |   Blockedby:         
    Patch:  0              |    Blocking:         
---------------------------+------------------------------------------------
 wxsvn-trunk yesterday, Visual Studio 2005 x64

 In msw/toplevel.cpp: 545

 dlgTemplate->style = MSWGetStyle(style, &dlgTemplate->dwExtendedStyle);

 Parameter 2 gives a C4328 warning in x64 compilation.
 The member 'dwExtendedStyle' is aligned on a 2-byte boundary. On x64
 systems, pointers to data expect the data to be aligned on a 4-byte
 boundary, so passing a pointer to 'dwExtendedStyle' could cause a
 'misalignment' system exception.

 dwExtendedStyle is part of a MS struct, so the struct cannot be changed.
 MSWGetStyle could be modified to accept a

 DWORD * __unaligned extendedStyle

 using the MS specific extension __unaligned to tell the compiler to
 generate code that accepts pointers to unaligned data types. But that
 would reqire the keyword __unaligned for all compilers.

 The patch here simply copies the value to a temporary variable on the
 stack, which will be 4-byte aligned, passes a pointer to that temporary
 and then copies the result back to dwExtendedStyle.

 The problem appears because wx is using and modifying dwExtendedStyle from
 a MS struct. This struct has a specific alignment (#pragma pack) which
 must not be changed, because the struct is used by the OS itself and must
 be backwards compatible.


--
Ticket URL: <http://trac.wxwidgets.org/ticket/9726>


More information about the wx-dev mailing list