ddraw: Don't interpret end padding as dwCaps2 for x64.

Dylan Smith dylan.ah.smith at gmail.com
Sat May 21 23:57:30 CDT 2011


4 bytes of padding are at the end of DDSURFACEDESC when compiling for
x64, because it contains a pointer field followed by an odd number
of DWORD fields. The padding has the same offset as the dwCaps2 field
within DDSURFACEDESC2, so was causing the ddraw dsurface test to fail in
MipMapCreationTest where the padding was left uninitialized.  Windows
didn't fail the same way, even with explicitly setting all the bits in
the padding before calling CreateSurface.
---
 dlls/ddraw/ddraw.c         |    2 ++
 dlls/ddraw/ddraw_private.h |    8 ++++++++
 dlls/ddraw/surface.c       |    2 ++
 3 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index 4a7e5ed..b3873a5 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -3123,6 +3123,8 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
     memset(&desc2, 0, sizeof(desc2));
     desc2.dwSize = sizeof(desc2);   /* For the struct copy */
     DD_STRUCT_COPY_BYSIZE(&desc2, DDSD);
+    if (DDSD->dwSize == sizeof(DDSURFACEDESC))
+        CLEAR_STRUCT_END_PADDING((DDSURFACEDESC*)&desc2, ddsCaps);
     desc2.dwSize = sizeof(desc2);   /* To override a possibly smaller size */
     desc2.u4.ddpfPixelFormat.dwSize=sizeof(DDPIXELFORMAT); /* Just to be sure */
 
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index 8aa69c1..6c17f1b 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -606,4 +606,12 @@ typedef struct
 
 #endif
 
+#define CLEAR_STRUCT_END_PADDING(struct_ptr, last_field)                                   \
+    do {                                                                                   \
+        char *__end = (char*)&(struct_ptr)->last_field + sizeof((struct_ptr)->last_field); \
+        size_t __size = sizeof(*struct_ptr) - (__end - (char*)(struct_ptr));               \
+        if (__size)                                                                        \
+            memset(__end, 0, __size);                                                      \
+    } while (0)
+
 HRESULT hr_ddraw_from_wined3d(HRESULT hr) DECLSPEC_HIDDEN;
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index f46c200..85c6a65 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -3568,6 +3568,8 @@ HRESULT ddraw_surface_init(IDirectDrawSurfaceImpl *surface, IDirectDrawImpl *ddr
     surface->surface_desc.dwSize = sizeof(DDSURFACEDESC2);
     surface->surface_desc.u4.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
     DD_STRUCT_COPY_BYSIZE(&surface->surface_desc, desc);
+    if (desc->dwSize == sizeof(DDSURFACEDESC))
+        CLEAR_STRUCT_END_PADDING((DDSURFACEDESC*)&surface->surface_desc, ddsCaps);
 
     surface->first_attached = surface;
     surface->ImplType = surface_type;
-- 
1.7.4.1



More information about the wine-patches mailing list