Browse Source

Make SDL_VERSION_ATLEAST future-proof against larger version numbers

This comparison normally happens at compile-time, not at runtime, so
it doesn't matter if it isn't optimal. This avoids incorrect comparison
if the minor version in SDL_COMPILEDVERSION and SDL_VERSIONNUM has more
than one digit, which would cause it to overflow from the hundreds place
into the thousands place.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Simon McVittie 3 years ago
parent
commit
f9a5cf77b8
1 changed files with 3 additions and 1 deletions
  1. 3 1
      include/SDL_version.h

+ 3 - 1
include/SDL_version.h

@@ -104,7 +104,9 @@ typedef struct SDL_version
  *  This macro will evaluate to true if compiled with SDL at least X.Y.Z.
  */
 #define SDL_VERSION_ATLEAST(X, Y, Z) \
-    (SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
+    ((SDL_MAJOR_VERSION >= X) && \
+     (SDL_MAJOR_VERSION > X || SDL_MINOR_VERSION >= Y) && \
+     (SDL_MAJOR_VERSION > X || SDL_MINOR_VERSION > Y || SDL_PATCHLEVEL >= Z))
 
 /**
  * Get the version of SDL that is linked against your program.