diff mbox series

[alsa-utils,4/5] aplay: Handle upper bound in peak calculations

Message ID 20210824094756.12540-5-tiwai@suse.de (mailing list archive)
State New, archived
Headers show
Series aplay: Fix bugs in peak calculations | expand

Commit Message

Takashi Iwai Aug. 24, 2021, 9:47 a.m. UTC
Make sure that the calculated max_peak[] won't go beyond the sample
max resolution.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 aplay/aplay.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/aplay/aplay.c b/aplay/aplay.c
index 2543de5b6cd8..a51a37ba34bd 100644
--- a/aplay/aplay.c
+++ b/aplay/aplay.c
@@ -1898,6 +1898,8 @@  static void compute_max_peak(u_char *data, size_t samples)
 		max = 0x7fffffff;
 
 	for (c = 0; c < ichans; c++) {
+		if (max_peak[c] > max)
+			max_peak[c] = max;
 		if (bits_per_sample > 16)
 			perc[c] = max_peak[c] / (max / 100);
 		else