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

Unified Diff: core/src/fxcrt/fx_basic_util.cpp

Issue 1433513002: Revert "Revert "Revert "Revert "Cleanup some numeric code."""" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 1 month 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 | « core/src/fxcrt/fx_basic_gcc.cpp ('k') | core/src/fxcrt/fx_basic_wstring.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fxcrt/fx_basic_util.cpp
diff --git a/core/src/fxcrt/fx_basic_util.cpp b/core/src/fxcrt/fx_basic_util.cpp
index 46a0dec1e538884370b92f7865aa84d1fde13722..de027fea84807699e8c9f1da0323168ffa96f96f 100644
--- a/core/src/fxcrt/fx_basic_util.cpp
+++ b/core/src/fxcrt/fx_basic_util.cpp
@@ -4,13 +4,18 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include <cctype>
+
#include "../../include/fxcrt/fx_basic.h"
+#include "../../include/fxcrt/fx_ext.h"
+
#if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
#include <sys/types.h>
#include <dirent.h>
#else
#include <direct.h>
#endif
+
CFX_PrivateData::~CFX_PrivateData() {
ClearAll();
}
@@ -100,14 +105,16 @@ void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) {
bNegative = TRUE;
cc++;
}
- while (cc < len) {
- if (str[cc] < '0' || str[cc] > '9') {
+ while (cc < len && std::isdigit(str[cc])) {
+ // TODO(dsinclair): Are these two checks for overflow needed?
+ if (integer > std::numeric_limits<int>::max() / 10)
break;
- }
- integer = integer * 10 + str[cc] - '0';
- if (integer < 0) {
+ integer *= 10;
+
+ if (integer > std::numeric_limits<int>::max() - 9)
Tom Sepez 2015/11/04 20:33:11 Sorry, I blew it. We should be able to parse 4294
dsinclair 2015/11/04 21:31:28 Actually, this code is just broken. If we did over
dsinclair 2015/11/10 00:47:03 I put it back to the wrong way as that was what th
break;
- }
+ integer += FXSYS_toDecimalDigit(str[cc]);
+
cc++;
}
if (bNegative) {
@@ -144,7 +151,7 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
if (str[cc] == '.') {
break;
}
- value = value * 10 + str[cc] - '0';
+ value = value * 10 + FXSYS_toDecimalDigit(str[cc]);
cc++;
}
static const FX_FLOAT fraction_scales[] = {
@@ -155,7 +162,7 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
if (cc < len && str[cc] == '.') {
cc++;
while (cc < len) {
- value += fraction_scales[scale] * (str[cc] - '0');
+ value += fraction_scales[scale] * FXSYS_toDecimalDigit(str[cc]);
scale++;
if (scale == sizeof fraction_scales / sizeof(FX_FLOAT)) {
break;
« no previous file with comments | « core/src/fxcrt/fx_basic_gcc.cpp ('k') | core/src/fxcrt/fx_basic_wstring.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698