diff options
author | thestig <thestig@chromium.org> | 2016-06-23 19:57:45 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-23 19:57:45 -0700 |
commit | 29d447ae35101675a2a2d8bc1dcfca65de7f3929 (patch) | |
tree | 6a84b11413a53fb547e242bea6a5ddf55df7293a /core/fxcrt | |
parent | ce56557ef58facf2519f541d5cad33ea121b4c21 (diff) | |
download | pdfium-29d447ae35101675a2a2d8bc1dcfca65de7f3929.tar.xz |
Improve hint table validation checks.
Check required hint table dictionary entries and make sure they:
- Exist.
- Are of the right type.
Along the way:
- Fix FX_atonum() to not have a non-const pass-by-ref param.
- Simplify code in CPDF_StreamContentParser.
- Make CPDF_Number::IsInteger() a const method.
BUG=610555
Review-Url: https://codereview.chromium.org/2095763003
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/fx_basic_util.cpp | 53 | ||||
-rw-r--r-- | core/fxcrt/include/fx_string.h | 2 |
2 files changed, 28 insertions, 27 deletions
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp index 12d3aefd1c..abd84a864f 100644 --- a/core/fxcrt/fx_basic_util.cpp +++ b/core/fxcrt/fx_basic_util.cpp @@ -18,33 +18,34 @@ #include <cctype> #include <memory> -void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) { - if (strc.Find('.') == -1) { - bInteger = TRUE; - int cc = 0; - pdfium::base::CheckedNumeric<int> integer = 0; - FX_STRSIZE len = strc.GetLength(); - bool bNegative = false; - if (strc[0] == '+') { - cc++; - } else if (strc[0] == '-') { - bNegative = true; - cc++; - } - while (cc < len && std::isdigit(strc[cc])) { - integer = integer * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc)); - if (!integer.IsValid()) - break; - cc++; - } - if (bNegative) { - integer = -integer; - } - *(int*)pData = integer.ValueOrDefault(0); - } else { - bInteger = FALSE; - *(FX_FLOAT*)pData = FX_atof(strc); +bool FX_atonum(const CFX_ByteStringC& strc, void* pData) { + if (strc.Find('.') != -1) { + FX_FLOAT* pFloat = static_cast<FX_FLOAT*>(pData); + *pFloat = FX_atof(strc); + return false; + } + + int cc = 0; + pdfium::base::CheckedNumeric<int> integer = 0; + bool bNegative = false; + if (strc[0] == '+') { + cc++; + } else if (strc[0] == '-') { + bNegative = true; + cc++; } + while (cc < strc.GetLength() && std::isdigit(strc[cc])) { + integer = integer * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc)); + if (!integer.IsValid()) + break; + cc++; + } + if (bNegative) + integer = -integer; + + int* pInt = static_cast<int*>(pData); + *pInt = integer.ValueOrDefault(0); + return true; } static const FX_FLOAT fraction_scales[] = { diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h index b0a89fd06c..c1bd82dd74 100644 --- a/core/fxcrt/include/fx_string.h +++ b/core/fxcrt/include/fx_string.h @@ -437,7 +437,7 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& str); inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) { return FX_atof(FX_UTF8Encode(wsStr.c_str(), wsStr.GetLength()).c_str()); } -void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData); +bool FX_atonum(const CFX_ByteStringC& str, void* pData); FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); #endif // CORE_FXCRT_INCLUDE_FX_STRING_H_ |