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.
This commit is contained in:
Ryan C. Gordon 2024-06-27 17:20:11 -04:00
parent 982feb7a65
commit 5631c6dbaa
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 5 additions and 1 deletions

View File

@ -983,9 +983,13 @@ static Thing *CreatePhysicalDeviceThing(const SDL_AudioDeviceID which, const SDL
SDL_Log("Adding physical audio device %u", (unsigned int) which); 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); thing = CreateThing(recording ? THING_PHYSDEV_RECORDING : THING_PHYSDEV, next_physdev_x, 170, 5, -1, -1, physdev_texture, NULL);
if (thing) { if (thing) {
const char *name = SDL_GetAudioDeviceName(which);
if (!name) {
name = "[Unnamed device]";
}
thing->data.physdev.devid = which; thing->data.physdev.devid = which;
thing->data.physdev.recording = recording; 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->ondrag = DeviceThing_ondrag;
thing->ondrop = PhysicalDeviceThing_ondrop; thing->ondrop = PhysicalDeviceThing_ondrop;
thing->ontick = PhysicalDeviceThing_ontick; thing->ontick = PhysicalDeviceThing_ontick;