From d3919b512ddf49a1b285468d209b4e110e7c7e30 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 16 Feb 2011 04:08:28 -0800 Subject: [PATCH] Fixed bug #1085 (Jump to NULL function pointer on ALSA_OpenDevice) Bruno 2010-12-16 02:41:51 PST Fix segfault in ALSA_OpenDevice() When alsa is linked to libsdl instead of being loaded on demand at runtime the alsa macro snd_pcm_hw_params_alloca(ptr); misbehaves. That macro calls snd_pcm_hw_params_sizeof() in order to determine the amount of memory to allocate but due to mis-placed define that function is replaced with ALSA_snd_pcm_hw_params_sizeof by preprocessor (and in case of link to alsa that function pointer is initialized to itself). Attached patch fixes the issue. --- src/audio/alsa/SDL_alsa_audio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index e7a367e83..f89e1b397 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -85,11 +85,11 @@ static int (*ALSA_snd_pcm_sw_params_set_start_threshold) static int (*ALSA_snd_pcm_sw_params) (snd_pcm_t *, snd_pcm_sw_params_t *); static int (*ALSA_snd_pcm_nonblock) (snd_pcm_t *, int); static int (*ALSA_snd_pcm_wait)(snd_pcm_t *, int); -#define snd_pcm_hw_params_sizeof ALSA_snd_pcm_hw_params_sizeof -#define snd_pcm_sw_params_sizeof ALSA_snd_pcm_sw_params_sizeof #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC +#define snd_pcm_hw_params_sizeof ALSA_snd_pcm_hw_params_sizeof +#define snd_pcm_sw_params_sizeof ALSA_snd_pcm_sw_params_sizeof static const char *alsa_library = SDL_AUDIO_DRIVER_ALSA_DYNAMIC; static void *alsa_handle = NULL;