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

Unified Diff: core/fxcrt/fx_basic_util.cpp

Issue 2640143003: Update safe numerics package to get bitwise ops (Closed)
Patch Set: 0 is a perfectly fine value of zero Created 3 years, 11 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
Index: core/fxcrt/fx_basic_util.cpp
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp
index e52ff2ecee0ac66e1de1355d895c199b1d01f919..f608e290a2a9236c93fa4cdd6a2da6206364bc44 100644
--- a/core/fxcrt/fx_basic_util.cpp
+++ b/core/fxcrt/fx_basic_util.cpp
@@ -12,12 +12,6 @@
#include <limits>
#include <memory>
-namespace {
-
-const int kDefaultIntValue = 0;
-
-} // namespace
-
bool FX_atonum(const CFX_ByteStringC& strc, void* pData) {
if (strc.Find('.') != -1) {
FX_FLOAT* pFloat = static_cast<FX_FLOAT*>(pData);
@@ -54,18 +48,19 @@ bool FX_atonum(const CFX_ByteStringC& strc, void* pData) {
// we've overflowed, reset to the default value.
if (bSigned) {
if (bNegative) {
- if (integer.ValueOrDefault(kDefaultIntValue) >
+ if (integer.ValueOrDefault(0) >
static_cast<uint32_t>(std::numeric_limits<int>::max()) + 1) {
- integer = kDefaultIntValue;
+ integer = 0;
}
- } else if (integer.ValueOrDefault(kDefaultIntValue) >
+ } else if (integer.ValueOrDefault(0) >
static_cast<uint32_t>(std::numeric_limits<int>::max())) {
- integer = kDefaultIntValue;
+ integer = 0;
}
}
// Switch back to the int space so we can flip to a negative if we need.
- int value = static_cast<int>(integer.ValueOrDefault(kDefaultIntValue));
+ uint32_t uValue = integer.ValueOrDefault(0);
+ int32_t value = static_cast<int>(uValue);
if (bNegative)
value = -value;

Powered by Google App Engine
This is Rietveld 408576698