Move UBSan warnings from a blacklist to the source
This is done to make UBSan testing more convenient in integration with projects using WebRTC
Some blacklist entries were obsolete so don't need a replacement
Also fix one of the warnings (thanks, kwiberg@)
BUG=webrtc:8189, webrtc:5486, webrtc:5491
Review-Url: https://codereview.webrtc.org/3009123002
Cr-Commit-Position: refs/heads/master@{#19682}
diff --git a/webrtc/rtc_base/random.cc b/webrtc/rtc_base/random.cc
index c0cf7fe..f6bfc08 100644
--- a/webrtc/rtc_base/random.cc
+++ b/webrtc/rtc_base/random.cc
@@ -12,6 +12,7 @@
#include <math.h>
#include "webrtc/rtc_base/checks.h"
+#include "webrtc/rtc_base/safe_conversions.h"
namespace webrtc {
@@ -40,11 +41,9 @@
int32_t Random::Rand(int32_t low, int32_t high) {
RTC_DCHECK(low <= high);
- // We rely on subtraction (and addition) to be the same for signed and
- // unsigned numbers in two-complement representation. Thus, although
- // high - low might be negative as an int, it is the correct difference
- // when interpreted as an unsigned.
- return Rand(high - low) + low;
+ const int64_t low_i64{low};
+ return rtc::dchecked_cast<int32_t>(
+ Rand(rtc::dchecked_cast<uint32_t>(high - low_i64)) + low_i64);
}
template <>