summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt')
-rw-r--r--core/fxcrt/fx_basic_gcc.cpp5
-rw-r--r--core/fxcrt/fx_basic_gcc_unittest.cpp11
2 files changed, 10 insertions, 6 deletions
diff --git a/core/fxcrt/fx_basic_gcc.cpp b/core/fxcrt/fx_basic_gcc.cpp
index 1b2f01ec89..c3afe1115b 100644
--- a/core/fxcrt/fx_basic_gcc.cpp
+++ b/core/fxcrt/fx_basic_gcc.cpp
@@ -39,7 +39,10 @@ IntType FXSYS_StrToInt(const CharType* str) {
num = num * 10 + val;
str++;
}
- return neg ? -num : num;
+ // When it is a negative value, -num should be returned. Since num may be of
+ // unsigned type, use ~num + 1 to avoid the warning of applying unary minus
+ // operator to unsigned type.
+ return neg ? ~num + 1 : num;
}
template <typename T, typename UT, typename STR_T>
diff --git a/core/fxcrt/fx_basic_gcc_unittest.cpp b/core/fxcrt/fx_basic_gcc_unittest.cpp
index c6913cfd82..73e7446de0 100644
--- a/core/fxcrt/fx_basic_gcc_unittest.cpp
+++ b/core/fxcrt/fx_basic_gcc_unittest.cpp
@@ -16,15 +16,16 @@ TEST(fxcrt, FXSYS_atoi) {
EXPECT_EQ(2345, FXSYS_atoi("+2345"));
// The max value.
EXPECT_EQ(2147483647, FXSYS_atoi("2147483647"));
- // The min value.
- EXPECT_EQ(-2147483648, FXSYS_atoi("-2147483648"));
+ // The min value. Written in -1 format to avoid "unary minus operator applied
+ // to unsigned type" warning.
+ EXPECT_EQ(-2147483647 - 1, FXSYS_atoi("-2147483648"));
// With invalid char.
EXPECT_EQ(9, FXSYS_atoi("9x9"));
// Out of range values.
EXPECT_EQ(2147483647, FXSYS_atoi("2147483623423412348"));
EXPECT_EQ(2147483647, FXSYS_atoi("2147483648"));
- EXPECT_EQ(-2147483648, FXSYS_atoi("-2147483650"));
+ EXPECT_EQ(-2147483647 - 1, FXSYS_atoi("-2147483650"));
}
TEST(fxcrt, FXSYS_atoi64) {
@@ -58,13 +59,13 @@ TEST(fxcrt, FXSYS_wtoi) {
// The max value.
EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483647"));
// The min value.
- EXPECT_EQ(-2147483648, FXSYS_wtoi(L"-2147483648"));
+ EXPECT_EQ(-2147483647 - 1, FXSYS_wtoi(L"-2147483648"));
EXPECT_EQ(9, FXSYS_wtoi64(L"9x9"));
// Out of range values.
EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483623423412348"));
EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483648"));
- EXPECT_EQ(-2147483648, FXSYS_wtoi(L"-2147483652"));
+ EXPECT_EQ(-2147483647 - 1, FXSYS_wtoi(L"-2147483652"));
}
TEST(fxcrt, FXSYS_wtoi64) {