Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: webrtc/common_audio/signal_processing/signal_processing_unittest.cc

Issue 2002523002: Fix an UBSan error (signed overflow) in saturating addition and subtraction (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: review suggestions Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/common_audio/signal_processing/include/spl_inl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/common_audio/signal_processing/signal_processing_unittest.cc
diff --git a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc
index 108f459c894898e837dec760dd9f634601c08fa4..0dc0d378786a26bd6fcedba33bf81945907f81bb 100644
--- a/webrtc/common_audio/signal_processing/signal_processing_unittest.cc
+++ b/webrtc/common_audio/signal_processing/signal_processing_unittest.cc
@@ -8,6 +8,9 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <algorithm>
+#include <sstream>
+
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
@@ -118,26 +121,25 @@ TEST_F(SplTest, InlineTest) {
EXPECT_EQ(104, WebRtcSpl_AddSatW16(a16, b16));
EXPECT_EQ(138, WebRtcSpl_SubSatW16(a16, b16));
+}
- EXPECT_EQ(109410, WebRtcSpl_AddSatW32(a32, b32));
- EXPECT_EQ(112832, WebRtcSpl_SubSatW32(a32, b32));
-
- a32 = 0x80000000;
- b32 = 0x80000000;
- // Cast to signed int to avoid compiler complaint on gtest.h.
- EXPECT_EQ(static_cast<int>(0x80000000), WebRtcSpl_AddSatW32(a32, b32));
- a32 = 0x7fffffff;
- b32 = 0x7fffffff;
- EXPECT_EQ(0x7fffffff, WebRtcSpl_AddSatW32(a32, b32));
- a32 = 0;
- b32 = 0x80000000;
- EXPECT_EQ(0x7fffffff, WebRtcSpl_SubSatW32(a32, b32));
- a32 = 0x7fffffff;
- b32 = 0x80000000;
- EXPECT_EQ(0x7fffffff, WebRtcSpl_SubSatW32(a32, b32));
- a32 = 0x80000000;
- b32 = 0x7fffffff;
- EXPECT_EQ(static_cast<int>(0x80000000), WebRtcSpl_SubSatW32(a32, b32));
+TEST_F(SplTest, AddSubSatW32) {
+ static constexpr int32_t kAddSubArgs[] = {
+ INT32_MIN, INT32_MIN + 1, -3, -2, -1, 0, 1, -1, 2,
+ 3, INT32_MAX - 1, INT32_MAX};
+ for (int32_t a : kAddSubArgs) {
+ for (int32_t b : kAddSubArgs) {
+ const int64_t sum = std::max<int64_t>(
+ INT32_MIN, std::min<int64_t>(INT32_MAX, static_cast<int64_t>(a) + b));
+ const int64_t diff = std::max<int64_t>(
+ INT32_MIN, std::min<int64_t>(INT32_MAX, static_cast<int64_t>(a) - b));
+ std::ostringstream ss;
+ ss << a << " +/- " << b << ": sum " << sum << ", diff " << diff;
+ SCOPED_TRACE(ss.str());
+ EXPECT_EQ(sum, WebRtcSpl_AddSatW32(a, b));
+ EXPECT_EQ(diff, WebRtcSpl_SubSatW32(a, b));
+ }
+ }
}
TEST_F(SplTest, MathOperationsTest) {
« no previous file with comments | « webrtc/common_audio/signal_processing/include/spl_inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698