SDL: cleanup SDL_GetAudioDeviceName

From 113109f8392b609a32534e488edaf82fa4d07cda Mon Sep 17 00:00:00 2001
From: pionere <[EMAIL REDACTED]>
Date: Wed, 19 Jan 2022 17:18:47 +0100
Subject: [PATCH] cleanup SDL_GetAudioDeviceName - drop unnecessary hascapture
 check - call SDL_InvalidParamError in case the index is out of range

---
 src/audio/SDL_audio.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 6b325a3203b..028debd49a9 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -1081,38 +1081,29 @@ SDL_GetNumAudioDevices(int iscapture)
 const char *
 SDL_GetAudioDeviceName(int index, int iscapture)
 {
-    const char *retval = NULL;
+    SDL_AudioDeviceItem *item;
+    int i;
+    const char *retval;
 
     if (!SDL_GetCurrentAudioDriver()) {
         SDL_SetError("Audio subsystem is not initialized");
         return NULL;
     }
 
-    if (iscapture && !current_audio.impl.HasCaptureSupport) {
-        SDL_SetError("No capture support");
-        return NULL;
-    }
-
-    if (index >= 0) {
-        SDL_AudioDeviceItem *item;
-        int i;
-
-        SDL_LockMutex(current_audio.detectionLock);
-        item = iscapture ? current_audio.inputDevices : current_audio.outputDevices;
-        i = iscapture ? current_audio.inputDeviceCount : current_audio.outputDeviceCount;
-        if (index < i) {
-            for (i--; i > index; i--, item = item->next) {
-                SDL_assert(item != NULL);
-            }
+    SDL_LockMutex(current_audio.detectionLock);
+    item = iscapture ? current_audio.inputDevices : current_audio.outputDevices;
+    i = iscapture ? current_audio.inputDeviceCount : current_audio.outputDeviceCount;
+    if (index >= 0 && index < i) {
+        for (i--; i > index; i--, item = item->next) {
             SDL_assert(item != NULL);
-            retval = item->name;
         }
-        SDL_UnlockMutex(current_audio.detectionLock);
-    }
-
-    if (retval == NULL) {
-        SDL_SetError("No such device");
+        SDL_assert(item != NULL);
+        retval = item->name;
+    } else {
+        SDL_InvalidParamError("index");
+        retval = NULL;
     }
+    SDL_UnlockMutex(current_audio.detectionLock);
 
     return retval;
 }