src/flac/encode.c: Fix undefined behaviour
authorErik de Castro Lopo <erikd@mega-nerd.com>
Mon, 7 Sep 2015 05:55:22 +0000 (15:55 +1000)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Mon, 7 Sep 2015 05:55:32 +0000 (15:55 +1000)
Patch-from: lvqcl <lvqcl.mail@gmail.com>

src/flac/encode.c

index d313f23..5408548 100644 (file)
@@ -2420,12 +2420,11 @@ FLAC__bool format_input(FLAC__int32 *dest[], unsigned wide_samples, FLAC__bool i
                        unsigned b;
                        for(b = sample = wide_sample = 0; wide_sample < wide_samples; wide_sample++)
                                for(channel = 0; channel < channels; channel++, sample++) {
-                                       FLAC__int32 t;
+                                       uint32_t t;
                                        t  = ubuffer.u8[b++]; t <<= 8;
                                        t |= ubuffer.u8[b++]; t <<= 8;
                                        t |= ubuffer.u8[b++];
-                                       t -= 0x800000;
-                                       out[channel][wide_sample] = t;
+                                       out[channel][wide_sample] = (FLAC__int32)t - 0x800000;
                                }
                }
                else {