mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 13:50:40 +01:00
Avoid undefined behavior in a division operation.
BUG: webrtc:5486 Change-Id: I2850fbec3283b81b49ee4f966349a94aabc2bf82 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215969 Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org> Reviewed-by: Artem Titov <titovartem@webrtc.org> Commit-Queue: Minyue Li <minyue@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33811}
This commit is contained in:
parent
6674b9879a
commit
5663ce9152
1 changed files with 3 additions and 4 deletions
|
@ -98,8 +98,7 @@ int32_t WebRtcSpl_DivResultInQ31(int32_t num, int32_t den)
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t RTC_NO_SANITIZE("signed-integer-overflow") // bugs.webrtc.org/5486
|
int32_t WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low)
|
||||||
WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low)
|
|
||||||
{
|
{
|
||||||
int16_t approx, tmp_hi, tmp_low, num_hi, num_low;
|
int16_t approx, tmp_hi, tmp_low, num_hi, num_low;
|
||||||
int32_t tmpW32;
|
int32_t tmpW32;
|
||||||
|
@ -111,8 +110,8 @@ WebRtcSpl_DivW32HiLow(int32_t num, int16_t den_hi, int16_t den_low)
|
||||||
tmpW32 = (den_hi * approx << 1) + ((den_low * approx >> 15) << 1);
|
tmpW32 = (den_hi * approx << 1) + ((den_low * approx >> 15) << 1);
|
||||||
// tmpW32 = den * approx
|
// tmpW32 = den * approx
|
||||||
|
|
||||||
tmpW32 = (int32_t)0x7fffffffL - tmpW32; // result in Q30 (tmpW32 = 2.0-(den*approx))
|
// result in Q30 (tmpW32 = 2.0-(den*approx))
|
||||||
// UBSan: 2147483647 - -2 cannot be represented in type 'int'
|
tmpW32 = (int32_t)((int64_t)0x7fffffffL - tmpW32);
|
||||||
|
|
||||||
// Store tmpW32 in hi and low format
|
// Store tmpW32 in hi and low format
|
||||||
tmp_hi = (int16_t)(tmpW32 >> 16);
|
tmp_hi = (int16_t)(tmpW32 >> 16);
|
||||||
|
|
Loading…
Reference in a new issue