Index: webrtc/base/checks.h |
diff --git a/webrtc/base/checks.h b/webrtc/base/checks.h |
index aa6725dec771f221c1ce56cc3f3f8b2c5805c790..653ed322e71d5d3de79eddc299c329d4abc60df2 100644 |
--- a/webrtc/base/checks.h |
+++ b/webrtc/base/checks.h |
@@ -36,6 +36,8 @@ NO_RETURN void rtc_FatalMessage(const char* file, int line, const char* msg); |
#include <sstream> |
#include <string> |
+#include "webrtc/base/safe_compare.h" |
+ |
// The macros here print a message to stderr and abort under various |
// conditions. All will accept additional stream messages. For example: |
// RTC_DCHECK_EQ(foo, bar) << "I'm printed when foo != bar."; |
@@ -96,10 +98,8 @@ namespace rtc { |
// Call RTC_EAT_STREAM_PARAMETERS with an argument that fails to compile if |
// values of the same types as |a| and |b| can't be compared with the given |
// operation, and that would evaluate |a| and |b| if evaluated. |
-#define RTC_EAT_STREAM_PARAMETERS_OP(op, a, b) \ |
- RTC_EAT_STREAM_PARAMETERS(((void)sizeof(std::declval<decltype(a)>() \ |
- op std::declval<decltype(b)>()), \ |
- (void)(a), (void)(b))) |
+#define RTC_EAT_STREAM_PARAMETERS_OP(op, a, b) \ |
+ RTC_EAT_STREAM_PARAMETERS(((void)rtc::safe_cmp::op(a, b))) |
// RTC_CHECK dies with a fatal error if condition is not true. It is *not* |
// controlled by NDEBUG or anything else, so the check will be executed |
@@ -158,35 +158,35 @@ std::string* MakeCheckOpString<std::string, std::string>( |
// The (int, int) specialization works around the issue that the compiler |
// will not instantiate the template version of the function on values of |
// unnamed enum type - see comment below. |
-#define DEFINE_RTC_CHECK_OP_IMPL(name, op) \ |
+#define DEFINE_RTC_CHECK_OP_IMPL(name) \ |
template <class t1, class t2> \ |
inline std::string* Check##name##Impl(const t1& v1, const t2& v2, \ |
const char* names) { \ |
- if (v1 op v2) \ |
+ if (rtc::safe_cmp::name(v1, v2)) \ |
return NULL; \ |
else \ |
return rtc::MakeCheckOpString(v1, v2, names); \ |
} \ |
inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \ |
- if (v1 op v2) \ |
+ if (rtc::safe_cmp::name(v1, v2)) \ |
return NULL; \ |
else \ |
return rtc::MakeCheckOpString(v1, v2, names); \ |
} |
-DEFINE_RTC_CHECK_OP_IMPL(EQ, ==) |
-DEFINE_RTC_CHECK_OP_IMPL(NE, !=) |
-DEFINE_RTC_CHECK_OP_IMPL(LE, <=) |
-DEFINE_RTC_CHECK_OP_IMPL(LT, < ) |
-DEFINE_RTC_CHECK_OP_IMPL(GE, >=) |
-DEFINE_RTC_CHECK_OP_IMPL(GT, > ) |
+DEFINE_RTC_CHECK_OP_IMPL(Eq) |
+DEFINE_RTC_CHECK_OP_IMPL(Ne) |
+DEFINE_RTC_CHECK_OP_IMPL(Le) |
+DEFINE_RTC_CHECK_OP_IMPL(Lt) |
+DEFINE_RTC_CHECK_OP_IMPL(Ge) |
+DEFINE_RTC_CHECK_OP_IMPL(Gt) |
#undef DEFINE_RTC_CHECK_OP_IMPL |
-#define RTC_CHECK_EQ(val1, val2) RTC_CHECK_OP(EQ, ==, val1, val2) |
-#define RTC_CHECK_NE(val1, val2) RTC_CHECK_OP(NE, !=, val1, val2) |
-#define RTC_CHECK_LE(val1, val2) RTC_CHECK_OP(LE, <=, val1, val2) |
-#define RTC_CHECK_LT(val1, val2) RTC_CHECK_OP(LT, < , val1, val2) |
-#define RTC_CHECK_GE(val1, val2) RTC_CHECK_OP(GE, >=, val1, val2) |
-#define RTC_CHECK_GT(val1, val2) RTC_CHECK_OP(GT, > , val1, val2) |
+#define RTC_CHECK_EQ(val1, val2) RTC_CHECK_OP(Eq, ==, val1, val2) |
+#define RTC_CHECK_NE(val1, val2) RTC_CHECK_OP(Ne, !=, val1, val2) |
+#define RTC_CHECK_LE(val1, val2) RTC_CHECK_OP(Le, <=, val1, val2) |
+#define RTC_CHECK_LT(val1, val2) RTC_CHECK_OP(Lt, <, val1, val2) |
+#define RTC_CHECK_GE(val1, val2) RTC_CHECK_OP(Ge, >=, val1, val2) |
+#define RTC_CHECK_GT(val1, val2) RTC_CHECK_OP(Gt, >, val1, val2) |
// The RTC_DCHECK macro is equivalent to RTC_CHECK except that it only generates |
// code in debug builds. It does reference the condition parameter in all cases, |
@@ -201,12 +201,12 @@ DEFINE_RTC_CHECK_OP_IMPL(GT, > ) |
#define RTC_DCHECK_GT(v1, v2) RTC_CHECK_GT(v1, v2) |
#else |
#define RTC_DCHECK(condition) RTC_EAT_STREAM_PARAMETERS(condition) |
-#define RTC_DCHECK_EQ(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(==, v1, v2) |
-#define RTC_DCHECK_NE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(!=, v1, v2) |
-#define RTC_DCHECK_LE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(<=, v1, v2) |
-#define RTC_DCHECK_LT(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(<, v1, v2) |
-#define RTC_DCHECK_GE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(>=, v1, v2) |
-#define RTC_DCHECK_GT(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(>, v1, v2) |
+#define RTC_DCHECK_EQ(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Eq, v1, v2) |
+#define RTC_DCHECK_NE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Ne, v1, v2) |
+#define RTC_DCHECK_LE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Le, v1, v2) |
+#define RTC_DCHECK_LT(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Lt, v1, v2) |
+#define RTC_DCHECK_GE(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Ge, v1, v2) |
+#define RTC_DCHECK_GT(v1, v2) RTC_EAT_STREAM_PARAMETERS_OP(Gt, v1, v2) |
#endif |
// This is identical to LogMessageVoidify but in name. |