Commit 42165fe8d1423c4fa3232ce6952459653f69a3e5

Ryan C. Gordon 2022-07-27T12:12:03

kmsdrm: slightly better device index hint parsing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index 92ecc2d..def7233 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -81,8 +81,9 @@ get_driindex(void)
 
     hint = SDL_GetHint(SDL_HINT_KMSDRM_DEVICE_INDEX);
     if (hint && *hint) {
-        const int idx = SDL_atoi(hint);
-        if (idx >= 0) {
+        char *endptr = NULL;
+        const int idx = (int) SDL_strtol(hint, &endptr, 10);
+        if ((*endptr == '\0') && (idx >= 0)) {  /* *endptr==0 means "whole string was a valid number" */
             return idx;  /* we'll take the user's request here. */
         }
     }