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

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

Issue 1755273002: Fix parsing of object numbers > 16,777,216. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 10 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/src/fxcrt/fx_basic_gcc.cpp
diff --git a/core/src/fxcrt/fx_basic_gcc.cpp b/core/src/fxcrt/fx_basic_gcc.cpp
index d905d6b498464cd4db47119deac8df2b8d61ad93..607f0955707b6fbcf408aad8ccafdc4fd979f362 100644
--- a/core/src/fxcrt/fx_basic_gcc.cpp
+++ b/core/src/fxcrt/fx_basic_gcc.cpp
@@ -13,20 +13,21 @@
template <class T>
T FXSYS_StrToInt(const FX_CHAR* str) {
- FX_BOOL neg = FALSE;
+ bool neg = false;
if (!str)
return 0;
- if (*str == '-') {
- neg = TRUE;
+ if (std::numeric_limits<T>::is_signed && *str == '-') {
+ neg = true;
str++;
}
T num = 0;
while (*str && std::isdigit(*str)) {
- if (num > (std::numeric_limits<T>::max() - 9) / 10)
+ T val = FXSYS_toDecimalDigit(*str);
+ if (num > (std::numeric_limits<T>::max() - val) / 10)
break;
- num = num * 10 + FXSYS_toDecimalDigit(*str);
+ num = num * 10 + val;
str++;
}
return neg ? -num : num;
@@ -34,20 +35,21 @@ T FXSYS_StrToInt(const FX_CHAR* str) {
template <class T>
T FXSYS_StrToInt(const FX_WCHAR* str) {
- FX_BOOL neg = FALSE;
+ bool neg = false;
if (!str)
return 0;
- if (*str == '-') {
- neg = TRUE;
+ if (std::numeric_limits<T>::is_signed && *str == '-') {
+ neg = true;
str++;
}
T num = 0;
while (*str && std::iswdigit(*str)) {
- if (num > (std::numeric_limits<T>::max() - 9) / 10)
+ T val = FXSYS_toDecimalDigitWide(*str);
Tom Sepez 2016/03/02 21:53:36 If you really want some fun, try overloading FXSYS
dsinclair 2016/03/02 22:09:17 Will do in a separate CL. https://bugs.chromium.or
+ if (num > (std::numeric_limits<T>::max() - val) / 10)
break;
- num = num * 10 + FXSYS_toDecimalDigitWide(*str);
+ num = num * 10 + val;
str++;
}
return neg ? -num : num;
@@ -93,6 +95,9 @@ extern "C" {
int32_t FXSYS_atoi(const FX_CHAR* str) {
return FXSYS_StrToInt<int32_t>(str);
}
+uint32_t FXSYS_atoui(const FX_CHAR* str) {
+ return FXSYS_StrToInt<uint32_t>(str);
+}
int32_t FXSYS_wtoi(const FX_WCHAR* str) {
return FXSYS_StrToInt<int32_t>(str);
}

Powered by Google App Engine
This is Rietveld 408576698