summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_basic_util.cpp
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-05-19 11:37:10 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-19 11:37:10 -0700
commitbc8a64029f898286c3dcad3a6cecdc98ef30b139 (patch)
treebd427e40a5b37f567845d3c1417e4ad206ff574b /core/fxcrt/fx_basic_util.cpp
parente97ea03201636021102e31473eadf507d781c60f (diff)
downloadpdfium-bc8a64029f898286c3dcad3a6cecdc98ef30b139.tar.xz
Correctly check for overflow in FX_atonum.
Instead of the existing method, use the CheckedNumeric class to check for overflow during conversion. BUG=chromium:596526 Review-Url: https://codereview.chromium.org/1992023003
Diffstat (limited to 'core/fxcrt/fx_basic_util.cpp')
-rw-r--r--core/fxcrt/fx_basic_util.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp
index abb2b9472a..aa36d56f38 100644
--- a/core/fxcrt/fx_basic_util.cpp
+++ b/core/fxcrt/fx_basic_util.cpp
@@ -94,11 +94,12 @@ void CFX_PrivateData::ClearAll() {
}
m_DataList.RemoveAll();
}
+
void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) {
if (strc.Find('.') == -1) {
bInteger = TRUE;
int cc = 0;
- int integer = 0;
+ pdfium::base::CheckedNumeric<int> integer = 0;
FX_STRSIZE len = strc.GetLength();
bool bNegative = false;
if (strc[0] == '+') {
@@ -108,21 +109,21 @@ void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) {
cc++;
}
while (cc < len && std::isdigit(strc[cc])) {
- // TODO(dsinclair): This is not the right way to handle overflow.
integer = integer * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc));
- if (integer < 0)
+ if (!integer.IsValid())
break;
cc++;
}
if (bNegative) {
integer = -integer;
}
- *(int*)pData = integer;
+ *(int*)pData = integer.ValueOrDefault(0);
} else {
bInteger = FALSE;
*(FX_FLOAT*)pData = FX_atof(strc);
}
}
+
FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
if (strc.IsEmpty())
return 0.0;