Mesa (master): glx/windows: Fix compilation with -Werror-format

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jun 7 18:40:08 UTC 2019


Module: Mesa
Branch: master
Commit: 87173ded6e26ac791fc7d71184c560ed9b747817
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=87173ded6e26ac791fc7d71184c560ed9b747817

Author: Jon Turney <jon.turney at dronecode.org.uk>
Date:   Thu Jun  6 16:44:08 2019 +0100

glx/windows: Fix compilation with -Werror-format

Fix compilation where the DWORD type is used with a format, after
-Werror-format added by c9c1e261.

Some Win32 API types are different fundamental types in the 32-bit and
64-bit versions. This problem is then further compounded by the fact
that whilst both 32-bit Cygwin and 32-bit MinGW use the ILP32 data
model, 64-bit MinGW uses the LLP64 data model, but 64-bit Cygwin uses
the LP64 data model. This makes it near impossible to write printf
format specifiers which are correct for all those targets.

In the Win32 API, DWORD is an unsigned, 32-bit type.  So, it is defined
in terms of an unsigned long, except in the LP64 data model used by
64-bit Cygwin, where it is an unsigned int.

It should always be safe to cast it to unsigned int and use %u or %x.

Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/glx/windows/windows_drawable.c | 6 +++---
 src/glx/windows/windowsgl.c        | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/glx/windows/windows_drawable.c b/src/glx/windows/windows_drawable.c
index 3d8227d3b7d..d1d79572b87 100644
--- a/src/glx/windows/windows_drawable.c
+++ b/src/glx/windows/windows_drawable.c
@@ -124,10 +124,10 @@ windows_create_drawable(int type, void *handle)
       d->callbacks = &pixmap_callbacks;
 
       // Access file mapping object by a name
-      snprintf(name, sizeof(name), "Local\\CYGWINX_WINDOWSDRI_%08lx", (uintptr_t)handle);
+      snprintf(name, sizeof(name), "Local\\CYGWINX_WINDOWSDRI_%08x", (unsigned int)(uintptr_t)handle);
       d->hSection = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name);
       if (!d->hSection)
-         printf("OpenFileMapping failed %x\n", GetLastError());
+         printf("OpenFileMapping failed %x\n", (int)GetLastError());
 
       // Create a screen-compatible DC
       d->dibDC = CreateCompatibleDC(NULL);
@@ -135,7 +135,7 @@ windows_create_drawable(int type, void *handle)
       // Map the shared memory section to access the BITMAPINFOHEADER
       pBmpHeader = (BITMAPINFOHEADER *)MapViewOfFile(d->hSection, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(BITMAPINFOHEADER));
       if (!pBmpHeader)
-         printf("MapViewOfFile failed %x\n", GetLastError());
+         printf("MapViewOfFile failed %x\n", (int)GetLastError());
 
       // Create a DIB using the file mapping
       d->hDIB = CreateDIBSection(d->dibDC, (BITMAPINFO *) pBmpHeader,
diff --git a/src/glx/windows/windowsgl.c b/src/glx/windows/windowsgl.c
index 56849da8371..73366b20ab8 100644
--- a/src/glx/windows/windowsgl.c
+++ b/src/glx/windows/windowsgl.c
@@ -217,7 +217,7 @@ int windows_bind_context(windowsContext *context, windowsDrawable *draw, windows
       read->callbacks->releasedc(read, readDc);
 
       if (!ret) {
-         printf("wglMakeContextCurrentARB error: %08x\n", GetLastError());
+         printf("wglMakeContextCurrentARB error: %08x\n", (int)GetLastError());
          return FALSE;
       }
    }
@@ -226,7 +226,7 @@ int windows_bind_context(windowsContext *context, windowsDrawable *draw, windows
       /* Otherwise, just use wglMakeCurrent */
       BOOL ret = wglMakeCurrent(drawDc, context->ctx);
       if (!ret) {
-         printf("wglMakeCurrent error: %08x\n", GetLastError());
+         printf("wglMakeCurrent error: %08x\n", (int)GetLastError());
          return FALSE;
       }
    }




More information about the mesa-commit mailing list