Fixed bug 2205 - SDL_GetAudioDeviceName returns default-device name on invalid index for default-device only drivers
authorSam Lantinga <slouken@libsdl.org>
Sun, 03 Nov 2013 11:13:06 -0800
changeset 7904915b9b6c9fa0
parent 7903 4d3e6191c807
child 7905 586eddae6340
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
     1.1 --- a/src/audio/SDL_audio.c	Sun Nov 03 11:00:28 2013 -0800
     1.2 +++ b/src/audio/SDL_audio.c	Sun Nov 03 11:13:06 2013 -0800
     1.3 @@ -722,10 +722,16 @@
     1.4      }
     1.5  
     1.6      if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) {
     1.7 +        if (index > 0) {
     1.8 +            goto no_such_device;
     1.9 +        }
    1.10          return DEFAULT_INPUT_DEVNAME;
    1.11      }
    1.12  
    1.13      if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
    1.14 +        if (index > 0) {
    1.15 +            goto no_such_device;
    1.16 +        }
    1.17          return DEFAULT_OUTPUT_DEVNAME;
    1.18      }
    1.19