Fix format string warnings for width-based integers The DJGPP compiler emits many warnings for conflicts between print format specifiers and argument types. To fix the warnings, I added `SDL_PRIx32` macros for use with `Sint32` and `Uint32` types. The macros alias those found in <inttypes.h> or fallback to a reasonable default. As an alternative, print arguments could be cast to plain old integers. I opted slightly for the current solution as it felt more technically correct, despite making the format strings more verbose.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h
index 5ca04e0..81e3a8c 100644
--- a/include/SDL_stdinc.h
+++ b/include/SDL_stdinc.h
@@ -223,7 +223,7 @@ typedef uint64_t Uint64;
/* @} *//* Basic data types */
-/* Make sure we have macros for printing 64 bit values.
+/* Make sure we have macros for printing width-based integers.
* <stdint.h> should define these but this is not true all platforms.
* (for example win32) */
#ifndef SDL_PRIs64
@@ -270,6 +270,34 @@ typedef uint64_t Uint64;
#define SDL_PRIX64 "llX"
#endif
#endif
+#ifndef SDL_PRIs32
+#ifdef PRId32
+#define SDL_PRIs32 PRId32
+#else
+#define SDL_PRIs32 "d"
+#endif
+#endif
+#ifndef SDL_PRIu32
+#ifdef PRIu32
+#define SDL_PRIu32 PRIu32
+#else
+#define SDL_PRIu32 "u"
+#endif
+#endif
+#ifndef SDL_PRIx32
+#ifdef PRIx32
+#define SDL_PRIx32 PRIx32
+#else
+#define SDL_PRIx32 "x"
+#endif
+#endif
+#ifndef SDL_PRIX32
+#ifdef PRIX32
+#define SDL_PRIX32 PRIX32
+#else
+#define SDL_PRIX32 "X"
+#endif
+#endif
/* Annotations to help code analysis tools */
#ifdef SDL_DISABLE_ANALYZE_MACROS
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
index 185bc38..88204fd 100644
--- a/src/audio/SDL_wave.c
+++ b/src/audio/SDL_wave.c
@@ -1871,7 +1871,7 @@ WaveLoad(SDL_RWops *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 **audio_buf,
while ((Uint64)RIFFend > (Uint64)chunk->position + chunk->length + (chunk->length & 1)) {
/* Abort after too many chunks or else corrupt files may waste time. */
if (chunkcount++ >= chunkcountlimit) {
- return SDL_SetError("Chunk count in WAVE file exceeds limit of %u", chunkcountlimit);
+ return SDL_SetError("Chunk count in WAVE file exceeds limit of %" SDL_PRIu32, chunkcountlimit);
}
result = WaveNextChunk(src, chunk);
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 8b4dfcf..f592869 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -751,7 +751,7 @@ SDLTest_PrintRenderer(SDL_RendererInfo * info)
SDL_Log(" Renderer %s:\n", info->name);
- SDL_snprintf(text, sizeof(text), " Flags: 0x%8.8X", info->flags);
+ SDL_snprintf(text, sizeof(text), " Flags: 0x%8.8" SDL_PRIX32, info->flags);
SDL_snprintfcat(text, sizeof(text), " (");
count = 0;
for (i = 0; i < sizeof(info->flags) * 8; ++i) {
@@ -767,7 +767,7 @@ SDLTest_PrintRenderer(SDL_RendererInfo * info)
SDL_snprintfcat(text, sizeof(text), ")");
SDL_Log("%s\n", text);
- SDL_snprintf(text, sizeof(text), " Texture formats (%d): ", info->num_texture_formats);
+ SDL_snprintf(text, sizeof(text), " Texture formats (%" SDL_PRIu32 "): ", info->num_texture_formats);
for (i = 0; i < (int) info->num_texture_formats; ++i) {
if (i > 0) {
SDL_snprintfcat(text, sizeof(text), ", ");
@@ -948,11 +948,11 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
mode.w, mode.h, mode.refresh_rate, bpp,
SDL_GetPixelFormatName(mode.format));
if (Rmask || Gmask || Bmask) {
- SDL_Log(" Red Mask = 0x%.8x\n", Rmask);
- SDL_Log(" Green Mask = 0x%.8x\n", Gmask);
- SDL_Log(" Blue Mask = 0x%.8x\n", Bmask);
+ SDL_Log(" Red Mask = 0x%.8" SDL_PRIx32 "\n", Rmask);
+ SDL_Log(" Green Mask = 0x%.8" SDL_PRIx32 "\n", Gmask);
+ SDL_Log(" Blue Mask = 0x%.8" SDL_PRIx32 "\n", Bmask);
if (Amask)
- SDL_Log(" Alpha Mask = 0x%.8x\n", Amask);
+ SDL_Log(" Alpha Mask = 0x%.8" SDL_PRIx32 "\n", Amask);
}
/* Print available fullscreen video modes */
@@ -969,14 +969,14 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
j, mode.w, mode.h, mode.refresh_rate, bpp,
SDL_GetPixelFormatName(mode.format));
if (Rmask || Gmask || Bmask) {
- SDL_Log(" Red Mask = 0x%.8x\n",
+ SDL_Log(" Red Mask = 0x%.8" SDL_PRIx32 "\n",
Rmask);
- SDL_Log(" Green Mask = 0x%.8x\n",
+ SDL_Log(" Green Mask = 0x%.8" SDL_PRIx32 "\n",
Gmask);
- SDL_Log(" Blue Mask = 0x%.8x\n",
+ SDL_Log(" Blue Mask = 0x%.8" SDL_PRIx32 "\n",
Bmask);
if (Amask)
- SDL_Log(" Alpha Mask = 0x%.8x\n",
+ SDL_Log(" Alpha Mask = 0x%.8" SDL_PRIx32 "\n",
Amask);
}
}
@@ -1256,10 +1256,11 @@ SDLTest_PrintEvent(SDL_Event * event)
case SDL_DISPLAYEVENT:
switch (event->display.event) {
case SDL_DISPLAYEVENT_ORIENTATION:
- SDL_Log("SDL EVENT: Display %d changed orientation to %s", event->display.display, DisplayOrientationName(event->display.data1));
+ SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " changed orientation to %s",
+ event->display.display, DisplayOrientationName(event->display.data1));
break;
default:
- SDL_Log("SDL EVENT: Display %d got unknown event 0x%4.4x",
+ SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " got unknown event 0x%4.4x",
event->display.display, event->display.event);
break;
}
@@ -1267,123 +1268,120 @@ SDLTest_PrintEvent(SDL_Event * event)
case SDL_WINDOWEVENT:
switch (event->window.event) {
case SDL_WINDOWEVENT_SHOWN:
- SDL_Log("SDL EVENT: Window %d shown", event->window.windowID);
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " shown", event->window.windowID);
break;
case SDL_WINDOWEVENT_HIDDEN:
- SDL_Log("SDL EVENT: Window %d hidden", event->window.windowID);
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " hidden", event->window.windowID);
break;
case SDL_WINDOWEVENT_EXPOSED:
- SDL_Log("SDL EVENT: Window %d exposed", event->window.windowID);
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " exposed", event->window.windowID);
break;
case SDL_WINDOWEVENT_MOVED:
- SDL_Log("SDL EVENT: Window %d moved to %d,%d",
- event->window.windowID, event->window.data1,
- event->window.data2);
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " moved to %" SDL_PRIs32 ",%" SDL_PRIs32,
+ event->window.windowID, event->window.data1, event->window.data2);
break;
case SDL_WINDOWEVENT_RESIZED:
- SDL_Log("SDL EVENT: Window %d resized to %dx%d",
- event->window.windowID, event->window.data1,
- event->window.data2);
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " resized to %" SDL_PRIs32 "x%" SDL_PRIs32,
+ event->window.windowID, event->window.data1, event->window.data2);
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
- SDL_Log("SDL EVENT: Window %d changed size to %dx%d",
- event->window.windowID, event->window.data1,
- event->window.data2);
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " changed size to %" SDL_PRIs32 "x%" SDL_PRIs32,
+ event->window.windowID, event->window.data1, event->window.data2);
break;
case SDL_WINDOWEVENT_MINIMIZED:
- SDL_Log("SDL EVENT: Window %d minimized", event->window.windowID);
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " minimized", event->window.windowID);
break;
case SDL_WINDOWEVENT_MAXIMIZED:
- SDL_Log("SDL EVENT: Window %d maximized", event->window.windowID);
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " maximized", event->window.windowID);
break;
case SDL_WINDOWEVENT_RESTORED:
- SDL_Log("SDL EVENT: Window %d restored", event->window.windowID);
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " restored", event->window.windowID);
break;
case SDL_WINDOWEVENT_ENTER:
- SDL_Log("SDL EVENT: Mouse entered window %d",
+ SDL_Log("SDL EVENT: Mouse entered window %" SDL_PRIu32 "",
event->window.windowID);
break;
case SDL_WINDOWEVENT_LEAVE:
- SDL_Log("SDL EVENT: Mouse left window %d", event->window.windowID);
+ SDL_Log("SDL EVENT: Mouse left window %" SDL_PRIu32 "", event->window.windowID);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
- SDL_Log("SDL EVENT: Window %d gained keyboard focus",
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " gained keyboard focus",
event->window.windowID);
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
- SDL_Log("SDL EVENT: Window %d lost keyboard focus",
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " lost keyboard focus",
event->window.windowID);
break;
case SDL_WINDOWEVENT_CLOSE:
- SDL_Log("SDL EVENT: Window %d closed", event->window.windowID);
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " closed", event->window.windowID);
break;
case SDL_WINDOWEVENT_TAKE_FOCUS:
- SDL_Log("SDL EVENT: Window %d take focus", event->window.windowID);
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " take focus", event->window.windowID);
break;
case SDL_WINDOWEVENT_HIT_TEST:
- SDL_Log("SDL EVENT: Window %d hit test", event->window.windowID);
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " hit test", event->window.windowID);
break;
default:
- SDL_Log("SDL EVENT: Window %d got unknown event 0x%4.4x",
+ SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " got unknown event 0x%4.4x",
event->window.windowID, event->window.event);
break;
}
break;
case SDL_KEYDOWN:
- SDL_Log("SDL EVENT: Keyboard: key pressed in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
+ SDL_Log("SDL EVENT: Keyboard: key pressed in window %" SDL_PRIu32 ": scancode 0x%08X = %s, keycode 0x%08" SDL_PRIX32 " = %s",
event->key.windowID,
event->key.keysym.scancode,
SDL_GetScancodeName(event->key.keysym.scancode),
event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
break;
case SDL_KEYUP:
- SDL_Log("SDL EVENT: Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
+ SDL_Log("SDL EVENT: Keyboard: key released in window %" SDL_PRIu32 ": scancode 0x%08X = %s, keycode 0x%08" SDL_PRIX32 " = %s",
event->key.windowID,
event->key.keysym.scancode,
SDL_GetScancodeName(event->key.keysym.scancode),
event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
break;
case SDL_TEXTEDITING:
- SDL_Log("SDL EVENT: Keyboard: text editing \"%s\" in window %d",
+ SDL_Log("SDL EVENT: Keyboard: text editing \"%s\" in window %" SDL_PRIu32,
event->edit.text, event->edit.windowID);
break;
case SDL_TEXTINPUT:
- SDL_Log("SDL EVENT: Keyboard: text input \"%s\" in window %d",
+ SDL_Log("SDL EVENT: Keyboard: text input \"%s\" in window %" SDL_PRIu32,
event->text.text, event->text.windowID);
break;
case SDL_KEYMAPCHANGED:
SDL_Log("SDL EVENT: Keymap changed");
break;
case SDL_MOUSEMOTION:
- SDL_Log("SDL EVENT: Mouse: moved to %d,%d (%d,%d) in window %d",
+ SDL_Log("SDL EVENT: Mouse: moved to %" SDL_PRIs32 ",%" SDL_PRIs32 " (%" SDL_PRIs32 ",%" SDL_PRIs32 ") in window %" SDL_PRIu32,
event->motion.x, event->motion.y,
event->motion.xrel, event->motion.yrel,
event->motion.windowID);
break;
case SDL_MOUSEBUTTONDOWN:
- SDL_Log("SDL EVENT: Mouse: button %d pressed at %d,%d with click count %d in window %d",
+ SDL_Log("SDL EVENT: Mouse: button %d pressed at %" SDL_PRIs32 ",%" SDL_PRIs32 " with click count %d in window %" SDL_PRIu32,
event->button.button, event->button.x, event->button.y, event->button.clicks,
event->button.windowID);
break;
case SDL_MOUSEBUTTONUP:
- SDL_Log("SDL EVENT: Mouse: button %d released at %d,%d with click count %d in window %d",
+ SDL_Log("SDL EVENT: Mouse: button %d released at %" SDL_PRIs32 ",%" SDL_PRIs32 " with click count %d in window %" SDL_PRIu32,
event->button.button, event->button.x, event->button.y, event->button.clicks,
event->button.windowID);
break;
case SDL_MOUSEWHEEL:
- SDL_Log("SDL EVENT: Mouse: wheel scrolled %d in x and %d in y (reversed: %d) in window %d",
+ SDL_Log("SDL EVENT: Mouse: wheel scrolled %" SDL_PRIs32 " in x and %" SDL_PRIs32 " in y (reversed: %" SDL_PRIu32 ") in window %" SDL_PRIu32,
event->wheel.x, event->wheel.y, event->wheel.direction, event->wheel.windowID);
break;
case SDL_JOYDEVICEADDED:
- SDL_Log("SDL EVENT: Joystick index %d attached",
+ SDL_Log("SDL EVENT: Joystick index %" SDL_PRIs32 " attached",
event->jdevice.which);
break;
case SDL_JOYDEVICEREMOVED:
- SDL_Log("SDL EVENT: Joystick %d removed",
+ SDL_Log("SDL EVENT: Joystick %" SDL_PRIs32 " removed",
event->jdevice.which);
break;
case SDL_JOYBALLMOTION:
- SDL_Log("SDL EVENT: Joystick %d: ball %d moved by %d,%d",
+ SDL_Log("SDL EVENT: Joystick %" SDL_PRIs32 ": ball %d moved by %d,%d",
event->jball.which, event->jball.ball, event->jball.xrel,
event->jball.yrel);
break;
@@ -1419,40 +1417,40 @@ SDLTest_PrintEvent(SDL_Event * event)
position = "LEFTUP";
break;
}
- SDL_Log("SDL EVENT: Joystick %d: hat %d moved to %s", event->jhat.which,
- event->jhat.hat, position);
+ SDL_Log("SDL EVENT: Joystick %" SDL_PRIs32 ": hat %d moved to %s",
+ event->jhat.which, event->jhat.hat, position);
}
break;
case SDL_JOYBUTTONDOWN:
- SDL_Log("SDL EVENT: Joystick %d: button %d pressed",
+ SDL_Log("SDL EVENT: Joystick %" SDL_PRIs32 ": button %d pressed",
event->jbutton.which, event->jbutton.button);
break;
case SDL_JOYBUTTONUP:
- SDL_Log("SDL EVENT: Joystick %d: button %d released",
+ SDL_Log("SDL EVENT: Joystick %" SDL_PRIs32 ": button %d released",
event->jbutton.which, event->jbutton.button);
break;
case SDL_CONTROLLERDEVICEADDED:
- SDL_Log("SDL EVENT: Controller index %d attached",
+ SDL_Log("SDL EVENT: Controller index %" SDL_PRIs32 " attached",
event->cdevice.which);
break;
case SDL_CONTROLLERDEVICEREMOVED:
- SDL_Log("SDL EVENT: Controller %d removed",
+ SDL_Log("SDL EVENT: Controller %" SDL_PRIs32 " removed",
event->cdevice.which);
break;
case SDL_CONTROLLERAXISMOTION:
- SDL_Log("SDL EVENT: Controller %d axis %d ('%s') value: %d",
+ SDL_Log("SDL EVENT: Controller %" SDL_PRIs32 " axis %d ('%s') value: %d",
event->caxis.which,
event->caxis.axis,
ControllerAxisName((SDL_GameControllerAxis)event->caxis.axis),
event->caxis.value);
break;
case SDL_CONTROLLERBUTTONDOWN:
- SDL_Log("SDL EVENT: Controller %d button %d ('%s') down",
+ SDL_Log("SDL EVENT: Controller %" SDL_PRIs32 "button %d ('%s') down",
event->cbutton.which, event->cbutton.button,
ControllerButtonName((SDL_GameControllerButton)event->cbutton.button));
break;
case SDL_CONTROLLERBUTTONUP:
- SDL_Log("SDL EVENT: Controller %d button %d ('%s') up",
+ SDL_Log("SDL EVENT: Controller %" SDL_PRIs32 " button %d ('%s') up",
event->cbutton.which, event->cbutton.button,
ControllerButtonName((SDL_GameControllerButton)event->cbutton.button));
break;
@@ -1527,10 +1525,10 @@ SDLTest_PrintEvent(SDL_Event * event)
SDL_Log("SDL EVENT: Quit requested");
break;
case SDL_USEREVENT:
- SDL_Log("SDL EVENT: User event %d", event->user.code);
+ SDL_Log("SDL EVENT: User event %" SDL_PRIs32, event->user.code);
break;
default:
- SDL_Log("Unknown event 0x%4.4x", event->type);
+ SDL_Log("Unknown event 0x%4.4" SDL_PRIu32, event->type);
break;
}
}
@@ -1911,7 +1909,8 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
char message[256];
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
- SDL_snprintf(message, sizeof(message), "(%i, %i), rel (%i, %i)\n", lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel);
+ SDL_snprintf(message, sizeof(message), "(%" SDL_PRIs32 ", %" SDL_PRIs32 "), rel (%" SDL_PRIs32 ", %" SDL_PRIs32 ")\n",
+ lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Last mouse position", message, window);
break;
}
diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c
index 6ecb10b..67445c7 100644
--- a/src/video/SDL_bmp.c
+++ b/src/video/SDL_bmp.c
@@ -306,7 +306,7 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
}
}
if (biWidth <= 0 || biHeight == 0) {
- SDL_SetError("BMP file with bad dimensions (%dx%d)", biWidth, biHeight);
+ SDL_SetError("BMP file with bad dimensions (%" SDL_PRIs32 "x%" SDL_PRIs32 ")", biWidth, biHeight);
was_error = SDL_TRUE;
goto done;
}
diff --git a/src/video/dummy/SDL_nullframebuffer.c b/src/video/dummy/SDL_nullframebuffer.c
index 6cad41d..781ea3b 100644
--- a/src/video/dummy/SDL_nullframebuffer.c
+++ b/src/video/dummy/SDL_nullframebuffer.c
@@ -69,7 +69,7 @@ int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect
/* Send the data to the display */
if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
char file[128];
- SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
+ SDL_snprintf(file, sizeof(file), "SDL_window%" SDL_PRIu32 "-%8.8d.bmp",
SDL_GetWindowID(window), ++frame_number);
SDL_SaveBMP(surface, file);
}