From 5631c6dbaaafb532a75654e0da4b9846940ca5d6 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 27 Jun 2024 17:20:11 -0400 Subject: [PATCH] testaudio: Don't crash if SDL_GetAudioDeviceName() returns NULL. It definitely will for default devices, so this crash is real, but it's also good defensive coding if something blows up unexpectedly. Fixes #10130. --- test/testaudio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/testaudio.c b/test/testaudio.c index c2951acaf..f32ea28f7 100644 --- a/test/testaudio.c +++ b/test/testaudio.c @@ -983,9 +983,13 @@ static Thing *CreatePhysicalDeviceThing(const SDL_AudioDeviceID which, const SDL SDL_Log("Adding physical audio device %u", (unsigned int) which); thing = CreateThing(recording ? THING_PHYSDEV_RECORDING : THING_PHYSDEV, next_physdev_x, 170, 5, -1, -1, physdev_texture, NULL); if (thing) { + const char *name = SDL_GetAudioDeviceName(which); + if (!name) { + name = "[Unnamed device]"; + } thing->data.physdev.devid = which; thing->data.physdev.recording = recording; - thing->data.physdev.name = SDL_strdup(SDL_GetAudioDeviceName(which)); + thing->data.physdev.name = SDL_strdup(name); thing->ondrag = DeviceThing_ondrag; thing->ondrop = PhysicalDeviceThing_ondrop; thing->ontick = PhysicalDeviceThing_ontick;