Commit 25f9ed87ff6947d9576fc9d79dee0784e638ac58

Sebastian Krzyszkowiak 2021-08-10T13:10:36

audio: Fix false positives in driver name comparison Without this change, driver names don't get matched correctly; for example "a" can get matched with "alsa" since it only checks whether the string matches up to the length of the requested driver name.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index dff8d08..4a6cbc8 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -980,7 +980,8 @@ SDL_AudioInit(const char *driver_name)
                                                                      : SDL_strlen(driver_attempt);
 
             for (i = 0; bootstrap[i]; ++i) {
-                if (SDL_strncasecmp(bootstrap[i]->name, driver_attempt, driver_attempt_len) == 0) {
+                if ((driver_attempt_len == SDL_strlen(bootstrap[i]->name)) &&
+                    (SDL_strncasecmp(bootstrap[i]->name, driver_attempt, driver_attempt_len) == 0)) {
                     tried_to_init = 1;
                     SDL_zero(current_audio);
                     current_audio.name = bootstrap[i]->name;