diff mbox series

[alsa-utils,3/5] aplay: Don't pass most negative integer to abs() in peak calculations

Message ID 20210824094756.12540-4-tiwai@suse.de
State New
Headers show
Series [alsa-utils,1/5] aplay: Fix conversion of unsigned samples in peak calculation | expand

Commit Message

Takashi Iwai Aug. 24, 2021, 9:47 a.m. UTC
The return value from abs() for the most negative integer is
undefined.  Cap it properly for the 32bit sample handling.

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

Patch

diff --git a/aplay/aplay.c b/aplay/aplay.c
index c884346c9f25..2543de5b6cd8 100644
--- a/aplay/aplay.c
+++ b/aplay/aplay.c
@@ -1874,7 +1874,10 @@  static void compute_max_peak(u_char *data, size_t samples)
 			else
 				val = be32toh(*valp);
 			val ^= mask;
-			val = abs(val);
+			if (val == 0x80000000U)
+				val = 0x7fffffff;
+			else
+				val = abs(val);
 			if (max_peak[c] < val)
 				max_peak[c] = val;
 			valp++;