Enable UBSan float-cast-overflow warnings and fix existing ones
BUG=webrtc:8204
Review-Url: https://codereview.webrtc.org/3007153003
Cr-Original-Commit-Position: refs/heads/master@{#19694}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 30431d5acd6225dc66f4fe49498376377f4f87e9
diff --git a/BUILD.gn b/BUILD.gn
index 4216bd3..210d208 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -93,6 +93,10 @@
ldflags += [ "-fsanitize-coverage=${rtc_sanitize_coverage}" ]
}
+ if (is_ubsan) {
+ cflags += [ "-fsanitize=float-cast-overflow" ]
+ }
+
# TODO(GYP): Support these in GN.
# if (is_bsd) {
# defines += [ "BSD" ]
diff --git a/media/base/rtpdataengine.cc b/media/base/rtpdataengine.cc
index 89099e7..d7aa32f 100644
--- a/media/base/rtpdataengine.cc
+++ b/media/base/rtpdataengine.cc
@@ -18,6 +18,7 @@
#include "webrtc/rtc_base/helpers.h"
#include "webrtc/rtc_base/logging.h"
#include "webrtc/rtc_base/ratelimiter.h"
+#include "webrtc/rtc_base/sanitizer.h"
#include "webrtc/rtc_base/stringutils.h"
namespace cricket {
@@ -74,9 +75,12 @@
}
}
-void RtpClock::Tick(double now, int* seq_num, uint32_t* timestamp) {
+void RTC_NO_SANITIZE("float-cast-overflow") // bugs.webrtc.org/8204
+RtpClock::Tick(double now, int* seq_num, uint32_t* timestamp) {
*seq_num = ++last_seq_num_;
*timestamp = timestamp_offset_ + static_cast<uint32_t>(now * clockrate_);
+ // UBSan: 5.92374e+10 is outside the range of representable values of type
+ // 'unsigned int'
}
const DataCodec* FindUnknownCodec(const std::vector<DataCodec>& codecs) {
diff --git a/modules/audio_processing/level_controller/level_controller.cc b/modules/audio_processing/level_controller/level_controller.cc
index 028501c..6edae5c 100644
--- a/modules/audio_processing/level_controller/level_controller.cc
+++ b/modules/audio_processing/level_controller/level_controller.cc
@@ -49,7 +49,7 @@
for (size_t k = 0; k < audio.num_channels(); ++k) {
float channel_energy =
std::accumulate(audio.channels_const_f()[k],
- audio.channels_const_f()[k] + audio.num_frames(), 0,
+ audio.channels_const_f()[k] + audio.num_frames(), 0.f,
[](float a, float b) -> float { return a + b * b; });
energy = std::max(channel_energy, energy);
}