Avoid integer overflow detected by the compiler.
Trying to calculate std::abs(min_int) results in an int overflow. Original author: asmok@. Bug: None Change-Id: I984e9ba4f48411a583a55cc3f9c66c9a1cc8dc92 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/318120 Reviewed-by: Per Åhgren <peah@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#40660}
This commit is contained in:
parent
d23d450a50
commit
83a95f748f
@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "common_audio/signal_processing/include/signal_processing_library.h"
|
||||
@ -67,7 +68,8 @@ int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) {
|
||||
RTC_DCHECK_GT(length, 0);
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
absolute = abs((int)vector[i]);
|
||||
absolute =
|
||||
(vector[i] != INT_MIN) ? abs((int)vector[i]) : INT_MAX + (uint32_t)1;
|
||||
if (absolute > maximum) {
|
||||
maximum = absolute;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user