Fix UBSan errors (left shift of negative value)
BUG=chromium:603501
Review-Url: https://codereview.webrtc.org/1988723002
Cr-Commit-Position: refs/heads/master@{#12775}
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/get_lsp_poly.c b/webrtc/modules/audio_coding/codecs/ilbc/get_lsp_poly.c
index 62a6864..a8375af 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/get_lsp_poly.c
+++ b/webrtc/modules/audio_coding/codecs/ilbc/get_lsp_poly.c
@@ -65,15 +65,15 @@
{
/* Compute f[j] = f[j] + tmp*f[j-1] + f[j-2]; */
high = (int16_t)(fPtr[-1] >> 16);
- low = (int16_t)((fPtr[-1] - ((int32_t)high << 16)) >> 1);
+ low = (int16_t)((fPtr[-1] & 0xffff) >> 1);
- tmpW32 = ((high * *lspPtr) << 2) + (((low * *lspPtr) >> 15) << 2);
+ tmpW32 = 4 * high * *lspPtr + 4 * ((low * *lspPtr) >> 15);
(*fPtr) += fPtr[-2];
(*fPtr) -= tmpW32;
fPtr--;
}
- *fPtr -= *lspPtr << 10;
+ *fPtr -= *lspPtr * (1 << 10);
fPtr+=i;
lspPtr+=2;
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/hp_output.c b/webrtc/modules/audio_coding/codecs/ilbc/hp_output.c
index bd101bf..8b18c04 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/hp_output.c
+++ b/webrtc/modules/audio_coding/codecs/ilbc/hp_output.c
@@ -48,7 +48,7 @@
tmpW32 = (tmpW32>>15);
tmpW32 += y[0] * ba[3]; /* (-a[1])*y[i-1] (high part) */
tmpW32 += y[2] * ba[4]; /* (-a[2])*y[i-2] (high part) */
- tmpW32 = (tmpW32<<1);
+ tmpW32 *= 2;
tmpW32 += signal[i] * ba[0]; /* b[0]*x[0] */
tmpW32 += x[0] * ba[1]; /* b[1]*x[i-1] */
@@ -77,11 +77,11 @@
} else if (tmpW32<-268435456) {
tmpW32 = WEBRTC_SPL_WORD32_MIN;
} else {
- tmpW32 <<= 3;
+ tmpW32 *= 8;
}
y[0] = (int16_t)(tmpW32 >> 16);
- y[1] = (int16_t)((tmpW32 - (y[0] << 16)) >> 1);
+ y[1] = (int16_t)((tmpW32 & 0xffff) >> 1);
}