alsa: Make device enumeration robust against weird results with NULL strings.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 04 Apr 2016 22:49:13 -0400
changeset 10142 bc8ac6c0cd98
parent 10141 fe9cf7c678f4
child 10143 14719cd1bde2
alsa: Make device enumeration robust against weird results with NULL strings.
src/audio/alsa/SDL_alsa_audio.c
--- a/src/audio/alsa/SDL_alsa_audio.c	Sat Apr 02 13:21:01 2016 -0300
+++ b/src/audio/alsa/SDL_alsa_audio.c	Mon Apr 04 22:49:13 2016 -0400
@@ -668,12 +668,17 @@
 static void
 add_device(const int iscapture, const char *name, const char *_desc)
 {
-    char *desc = SDL_strdup(_desc);
+    char *desc = NULL;
     char *handle = NULL;
-    char *ptr;
+    char *ptr = NULL;
 
+    if (!name || !_desc) {
+        return;  /* nothing we can do with this...? */
+    }
+
+    desc = SDL_strdup(_desc);
     if (!desc) {
-        return;
+        return;  /* oh well, out of memory. Skip it. */
     }
 
     /* some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output" */