Commit f9a5cf77b8e8b4703a4ef6f4ba7f2394cb7ee562

Simon McVittie 2022-05-03T13:05:02

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>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
diff --git a/include/SDL_version.h b/include/SDL_version.h
index f24fa81..5bdff3b 100644
--- a/include/SDL_version.h
+++ b/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.