summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_basic_gcc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt/fx_basic_gcc.cpp')
-rw-r--r--core/fxcrt/fx_basic_gcc.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/core/fxcrt/fx_basic_gcc.cpp b/core/fxcrt/fx_basic_gcc.cpp
index 440f924795..c29c9956e2 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 == '-';
+ 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 (neg && std::numeric_limits<IntType>::is_signed) {
+ // Return MIN when the represented number is signed type and is smaller
+ // than the min value.
+ return std::numeric_limits<IntType>::min();
+ } else {
+ // Return MAX when the represented number is signed type and is larger
+ // than the max value, or the number is unsigned type and out of range.
+ return std::numeric_limits<IntType>::max();
+ }
+ }
num = num * 10 + val;
str++;