summaryrefslogtreecommitdiff
path: root/src/libFLAC/stream_decoder.c
diff options
context:
space:
mode:
authorErik de Castro Lopo <erikd@mega-nerd.com>2015-08-24 19:20:35 +1000
committerErik de Castro Lopo <erikd@mega-nerd.com>2015-08-24 19:21:51 +1000
commitfb273e469e358994034e79e882192ac5eb7c9d48 (patch)
tree9bdf0668fe3c363cce2f5271652a51a6a55427f8 /src/libFLAC/stream_decoder.c
parente3c8095336249182b6a8871747df3cc99640103a (diff)
downloadflac-fb273e469e358994034e79e882192ac5eb7c9d48.tar.gz
libFLAC/stream_decoder.c: Fix undefined behaviour
Found by compiling with -fsanitize=undefined and running the testsuite.
Diffstat (limited to 'src/libFLAC/stream_decoder.c')
-rw-r--r--src/libFLAC/stream_decoder.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/libFLAC/stream_decoder.c b/src/libFLAC/stream_decoder.c
index 519b0c32..77036bab 100644
--- a/src/libFLAC/stream_decoder.c
+++ b/src/libFLAC/stream_decoder.c
@@ -2115,7 +2115,7 @@ FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FL
#if 1
mid = decoder->private_->output[0][i];
side = decoder->private_->output[1][i];
- mid <<= 1;
+ mid = ((uint32_t) mid) << 1;
mid |= (side & 1); /* i.e. if 'side' is odd... */
decoder->private_->output[0][i] = (mid + side) >> 1;
decoder->private_->output[1][i] = (mid - side) >> 1;
@@ -2541,8 +2541,10 @@ FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsign
if(wasted_bits && do_full_decode) {
x = decoder->private_->frame.subframes[channel].wasted_bits;
- for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
- decoder->private_->output[channel][i] <<= x;
+ for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
+ uint32_t val = decoder->private_->output[channel][i];
+ decoder->private_->output[channel][i] = (val << x);
+ }
}
return true;