aplay: Handle 16bit sample negative overflow in peak calculations

The handling of 16bit samples in the peak calculations has a bug when
a sample with 0x8000 is passed.  As abs() treats 32bit int, it returns
0x8000.  And yet the code stores back into 16bit value again.

To fix that overflow, use 32bit value (i.e. val instead of sval) for
the further calculations.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2021-08-24 09:36:33 +02:00
parent 0ea7bfea83
commit 5c4bf63a94

View file

@ -1829,9 +1829,9 @@ static void compute_max_peak(u_char *data, size_t samples)
else else
sval = be16toh(*valp); sval = be16toh(*valp);
sval ^= mask; sval ^= mask;
sval = abs(sval); val = abs(sval);
if (max_peak[c] < sval) if (max_peak[c] < val)
max_peak[c] = sval; max_peak[c] = val;
valp++; valp++;
if (vumeter == VUMETER_STEREO) if (vumeter == VUMETER_STEREO)
c = !c; c = !c;