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

Unified Diff: core/fxcrt/fx_basic_gcc.cpp

Issue 1828873002: Fix FXSYS_StrToInt() (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | core/fxcrt/fx_basic_gcc_unittest.cpp » ('j') | core/fxcrt/fx_basic_gcc_unittest.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/fx_basic_gcc.cpp
diff --git a/core/fxcrt/fx_basic_gcc.cpp b/core/fxcrt/fx_basic_gcc.cpp
index 2c9c54c8b60bd26cf6d6772517c6ec2f7df007e9..91aa689cd0ec8844001a3d0bc55d7f45f7e3cf9c 100644
--- a/core/fxcrt/fx_basic_gcc.cpp
+++ b/core/fxcrt/fx_basic_gcc.cpp
@@ -16,15 +16,25 @@ IntType FXSYS_StrToInt(const CharType* str) {
if (!str)
return 0;
- bool neg = std::numeric_limits<IntType>::is_signed && *str == '-';
- if (neg)
+ // Process the sign.
+ bool neg = *str == '-';
dsinclair 2016/03/24 02:41:06 This loses the std::numeric_limits<IntType>::is_si
Wei Li 2016/03/24 17:31:25 I think eventually we may want to use std:strto? t
dsinclair 2016/03/24 18:10:11 Fair enough, think the conditional on 28 can still
Wei Li 2016/03/24 23:25:46 Done.
+ if (neg || *str == '+')
str++;
IntType num = 0;
while (*str && FXSYS_isDecimalDigit(*str)) {
IntType val = FXSYS_toDecimalDigit(*str);
- if (num > (std::numeric_limits<IntType>::max() - val) / 10)
- break;
+ if (num > (std::numeric_limits<IntType>::max() - val) / 10) {
+ if (std::numeric_limits<IntType>::is_signed) {
dsinclair 2016/03/24 01:40:44 I didn't make this change originally because I was
Wei Li 2016/03/24 02:27:42 I checked callers which mainly use this to process
+ // Return MAX or MIN when the represented number is larger than the max
+ // value or smaller than the min value.
+ return neg ? std::numeric_limits<IntType>::min()
+ : std::numeric_limits<IntType>::max();
+ } else {
+ // Return MAX when the represented number is out of range.
+ return std::numeric_limits<IntType>::max();
dsinclair 2016/03/24 02:41:06 If you put the is_signed check back at line 20 thi
+ }
+ }
num = num * 10 + val;
str++;
« no previous file with comments | « no previous file | core/fxcrt/fx_basic_gcc_unittest.cpp » ('j') | core/fxcrt/fx_basic_gcc_unittest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698