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

Unified Diff: base/numerics/safe_math_impl.h

Issue 2564493003: Cleanup sign checking in safe math code (Closed)
Patch Set: Created 4 years 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 | « base/numerics/safe_conversions_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/numerics/safe_math_impl.h
diff --git a/base/numerics/safe_math_impl.h b/base/numerics/safe_math_impl.h
index ae0a5b1d4f031d8228ee47172daf27153dd6ce77..f648d1642074f9071c66891e9bd2f4e8f7a7afb8 100644
--- a/base/numerics/safe_math_impl.h
+++ b/base/numerics/safe_math_impl.h
@@ -47,8 +47,8 @@ struct UnsignedOrFloatForSize<Numeric, false, true> {
template <typename T>
constexpr bool HasSignBit(T x) {
// Cast to unsigned since right shift on signed is undefined.
scottmg 2016/12/08 21:05:02 You're not casting to unsigned.
- return !!(static_cast<typename std::make_unsigned<T>::type>(x) >>
- PositionOfSignBit<T>::value);
+ return static_cast<typename std::make_signed<T>::type>(x) <
+ static_cast<typename std::make_signed<T>::type>(0);
}
// This wrapper undoes the standard integer promotions.
« no previous file with comments | « base/numerics/safe_conversions_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698