Re: [PATCH] pcm: softvol: fix signedness of tlv data type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

> -	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)(...);


Regards,
Clemens
_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel




[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux