[alsa-devel] horribly wrong code when --with-versioned is active

Takashi Iwai tiwai at suse.de
Tue Aug 6 07:57:20 CEST 2013


At Mon, 05 Aug 2013 23:46:09 +0200,
John Spencer wrote:
> 
> if --with-versioned is active (default), a couple of macros in pcm.c
> start generating some completely broken, __old-prefixed wrapper 
> functions, which then are getting used whenever the actual function is 
> called.
> 
> for example:
> snd_pcm_hw_params_set_buffer_time_near
> 
> __OLD_NEAR1(snd_pcm_hw_params_set_buffer_time_near, unsigned int);
> 
> ->
> 
> #define __OLD_NEAR1(name, ret_type) __P_OLD_NEAR1(__old_, name, ret_type)
> 
> ->
> 
> #define __P_OLD_NEAR1(pfx, name, ret_type) \
> ret_type pfx##name(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, ret_type 
> val, int *dir) \
> { \
>          if (INTERNAL(name)(pcm, params, &val, dir) < 0) \
>                  return 0; \
>          return (ret_type)val; \
> }
> 
> this will lead to generating a function 
> __old_snd_pcm_hw_params_set_buffer_time_near which expands to
> 
> unsigned int __old_snd_pcm_hw_params_set_buffer_time_near(snd_pcm_t 
> *pcm, snd_pcm_hw_params_t *params, ret_type val, int *dir)
> {
>          if snd1_pcm_hw_params_set_buffer_time_near(pcm, params, &val, 
> dir) < 0)
>                  return 0;
>          return (ret_type)val;
> }
> 
> there 2 bugs in there,
> 1) the real function gets passed a pointer to a pointer of unsigned, 
> which is then happily dereferenced and the original pointer used as an 
> int, and

The pointer cast between signed and unsigned is done normally in C.

> 2) the return type logic is wrong, in case of a non-error, the original 
> pointer will be returned instead of 0 to indicate success.

The val argument is no pointer but a value.


Takashi


More information about the Alsa-devel mailing list