From 517886a7f15886e016ee651b0fa68cae0aabc55a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 3 Nov 2013 11:13:06 -0800 Subject: [PATCH] Fixed bug 2205 - SDL_GetAudioDeviceName returns default-device name on invalid index for default-device only drivers norfanin The audio_enumerateAndNameAudioDevicesNegativeTests test in testautomation_audio.c reports a failure for SDL_GetAudioDeviceName when called on a driver that has only the default device. SDL_GetNumAudioDevices reports 1, but SDL_GetAudioDeviceName does not check if the index passed by the caller is in that range in this case. For positive numbers anyway. This can be reproduced with the dummy driver on Windows and Linux. --- src/audio/SDL_audio.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 5631bb2fd..d6d835351 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -722,10 +722,16 @@ SDL_GetAudioDeviceName(int index, int iscapture) } if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) { + if (index > 0) { + goto no_such_device; + } return DEFAULT_INPUT_DEVNAME; } if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) { + if (index > 0) { + goto no_such_device; + } return DEFAULT_OUTPUT_DEVNAME; }