[alsa-devel] [PATCH] pcm: softvol: fix signedness of tlv data type

Jörg Krause joerg.krause at embedded.rocks
Sun May 8 20:18:19 CEST 2016


Hello,

On Sa, 2016-05-07 at 09:06 +0200, Clemens Ladisch wrote:
> Jörg Krause wrote:
> > For the softvol plugin the TLV data are written wrong, e.g. for the
> > default values
> > of min_dB = -51 dB and max_dB = 0 dB, alsactl generates the
> > following state:
> > 
> >                         tlv '00000001000000080000000000000014'
> > 
> > As both min_dB and max_dB can be negative numbers, the tlv type
> > must not be
> > unsigned.
> 
> TLVs always are unsigned.  But they can contain bit patterns that are
> to
> be interpreted as signed.

I see!

> > -	unsigned int tlv[4];
> > +	int tlv[4];
> >  	tlv[0] = SND_CTL_TLVT_DB_SCALE;
> >  	tlv[1] = 2 * sizeof(int);
> >  	tlv[2] = svol->min_dB * 100;
> 
> The problem is that conversion of a negative floating-point number
> into
> an unsigned integer results in undefined behaviour, and on your
> architecture (whatever it is), this results in zero.
> 
> The correct way to handle this would be something like this:
> 
>   tlv[i] = (int)(...);

This fixes the issue for my ARM target, many thanks! I'll send an
updated version.

Many thanks for the review!

Best regards,
Jörg Krause


More information about the Alsa-devel mailing list