Title: [145580] trunk/Source/WTF
- Revision
- 145580
- Author
- oli...@apple.com
- Date
- 2013-03-12 14:05:37 -0700 (Tue, 12 Mar 2013)
Log Message
Make CheckedArithmetic slightly more sane
https://bugs.webkit.org/show_bug.cgi?id=112178
Reviewed by Geoffrey Garen.
Add an enum type for safeGet rather than using a bool,
and correctly handle unsigned * unsigned, when one value
is 0.
* wtf/CheckedArithmetic.h:
(WTF::ENUM_CLASS):
(WTF):
(WTF::operator+):
(WTF::operator-):
(WTF::operator*):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (145579 => 145580)
--- trunk/Source/WTF/ChangeLog 2013-03-12 21:04:42 UTC (rev 145579)
+++ trunk/Source/WTF/ChangeLog 2013-03-12 21:05:37 UTC (rev 145580)
@@ -1,3 +1,21 @@
+2013-03-12 Oliver Hunt <oli...@apple.com>
+
+ Make CheckedArithmetic slightly more sane
+ https://bugs.webkit.org/show_bug.cgi?id=112178
+
+ Reviewed by Geoffrey Garen.
+
+ Add an enum type for safeGet rather than using a bool,
+ and correctly handle unsigned * unsigned, when one value
+ is 0.
+
+ * wtf/CheckedArithmetic.h:
+ (WTF::ENUM_CLASS):
+ (WTF):
+ (WTF::operator+):
+ (WTF::operator-):
+ (WTF::operator*):
+
2013-03-11 Michael Saboff <msab...@apple.com>
Unreviewed build fix. Rolling out inadvertent setting of DATA_LOG_TO_FILE.
Modified: trunk/Source/WTF/wtf/CheckedArithmetic.h (145579 => 145580)
--- trunk/Source/WTF/wtf/CheckedArithmetic.h 2013-03-12 21:04:42 UTC (rev 145579)
+++ trunk/Source/WTF/wtf/CheckedArithmetic.h 2013-03-12 21:05:37 UTC (rev 145580)
@@ -27,6 +27,7 @@
#define CheckedArithmetic_h
#include <wtf/Assertions.h>
+#include <wtf/EnumClass.h>
#include <wtf/TypeTraits.h>
#include <limits>
@@ -66,6 +67,12 @@
namespace WTF {
+ENUM_CLASS(CheckedState)
+{
+ DidOverflow,
+ DidNotOverflow
+} ENUM_CLASS_END(CheckedState);
+
class CrashOnOverflow {
protected:
NO_RETURN_DUE_TO_CRASH void overflowed()
@@ -316,7 +323,7 @@
{
ResultType temp = lhs * rhs;
if (temp < lhs)
- return false;
+ return !rhs;
result = temp;
return true;
}
@@ -534,10 +541,12 @@
return m_value;
}
- bool safeGet(T& value) const WARN_UNUSED_RETURN
+ inline CheckedState safeGet(T& value) const WARN_UNUSED_RETURN
{
value = m_value;
- return this->hasOverflowed();
+ if (this->hasOverflowed())
+ return CheckedState::DidOverflow;
+ return CheckedState::DidNotOverflow;
}
// Mutating assignment
@@ -638,7 +647,7 @@
{
U x = 0;
V y = 0;
- bool overflowed = lhs.safeGet(x) || rhs.safeGet(y);
+ bool overflowed = lhs.safeGet(x) == CheckedState::DidOverflow || rhs.safeGet(y) == CheckedState::DidOverflow;
typename Result<U, V>::ResultType result = 0;
overflowed |= !safeAdd(x, y, result);
if (overflowed)
@@ -650,7 +659,7 @@
{
U x = 0;
V y = 0;
- bool overflowed = lhs.safeGet(x) || rhs.safeGet(y);
+ bool overflowed = lhs.safeGet(x) == CheckedState::DidOverflow || rhs.safeGet(y) == CheckedState::DidOverflow;
typename Result<U, V>::ResultType result = 0;
overflowed |= !safeSub(x, y, result);
if (overflowed)
@@ -662,7 +671,7 @@
{
U x = 0;
V y = 0;
- bool overflowed = lhs.safeGet(x) || rhs.safeGet(y);
+ bool overflowed = lhs.safeGet(x) == CheckedState::DidOverflow || rhs.safeGet(y) == CheckedState::DidOverflow;
typename Result<U, V>::ResultType result = 0;
overflowed |= !safeMultiply(x, y, result);
if (overflowed)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes