]> git.alsa-project.org Git - alsa-utils.git/commitdiff
aplay: Don't pass most negative integer to abs() in peak calculations
authorTakashi Iwai <tiwai@suse.de>
Tue, 24 Aug 2021 07:58:29 +0000 (09:58 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 24 Aug 2021 07:58:29 +0000 (09:58 +0200)
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

index c884346c9f25e790707d3235430d5fd6cb3a5386..2543de5b6cd842403523be57078350e5f660ddac 100644 (file)
@@ -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++;