Fixed bug #1085 (Jump to NULL function pointer on ALSA_OpenDevice)
authorSam Lantinga <slouken@libsdl.org>
Wed, 16 Feb 2011 04:08:28 -0800
changeset 5315192f2d605339
parent 5314 ead9bbbdcaf3
child 5317 901a9e9ff0b7
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
     1.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Wed Feb 16 03:59:39 2011 -0800
     1.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Wed Feb 16 04:08:28 2011 -0800
     1.3 @@ -85,11 +85,11 @@
     1.4  static int (*ALSA_snd_pcm_sw_params) (snd_pcm_t *, snd_pcm_sw_params_t *);
     1.5  static int (*ALSA_snd_pcm_nonblock) (snd_pcm_t *, int);
     1.6  static int (*ALSA_snd_pcm_wait)(snd_pcm_t *, int);
     1.7 -#define snd_pcm_hw_params_sizeof ALSA_snd_pcm_hw_params_sizeof
     1.8 -#define snd_pcm_sw_params_sizeof ALSA_snd_pcm_sw_params_sizeof
     1.9  
    1.10  
    1.11  #ifdef SDL_AUDIO_DRIVER_ALSA_DYNAMIC
    1.12 +#define snd_pcm_hw_params_sizeof ALSA_snd_pcm_hw_params_sizeof
    1.13 +#define snd_pcm_sw_params_sizeof ALSA_snd_pcm_sw_params_sizeof
    1.14  
    1.15  static const char *alsa_library = SDL_AUDIO_DRIVER_ALSA_DYNAMIC;
    1.16  static void *alsa_handle = NULL;