Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorIlya Zverev <zverik@textual.ru>2016-06-01 14:45:20 +0300
committerIlya Zverev <zverik@textual.ru>2016-06-01 14:45:20 +0300
commitf334f5b6a633df52d38bad18aea95be99292a38c (patch)
tree48fa8874393845f71709e0ff825f44e3ede34760 /base
parent4fca9a22bdbff4dcd08cd0d88664788830cd2b4f (diff)
[tests] Correctly process empty strings in to_whatever
Diffstat (limited to 'base')
-rw-r--r--base/base_tests/string_utils_test.cpp3
-rw-r--r--base/string_utils.cpp6
2 files changed, 6 insertions, 3 deletions
diff --git a/base/base_tests/string_utils_test.cpp b/base/base_tests/string_utils_test.cpp
index 684a33a527..aa7e79074d 100644
--- a/base/base_tests/string_utils_test.cpp
+++ b/base/base_tests/string_utils_test.cpp
@@ -238,6 +238,9 @@ UNIT_TEST(to_uint64)
uint64_t i;
string s;
+ s = "";
+ TEST(!strings::to_uint64(s, i), ());
+
s = "0";
TEST(strings::to_uint64(s, i), ());
TEST_EQUAL(0, i, ());
diff --git a/base/string_utils.cpp b/base/string_utils.cpp
index cd9a1101ad..d5fe4d7c43 100644
--- a/base/string_utils.cpp
+++ b/base/string_utils.cpp
@@ -46,7 +46,7 @@ namespace
template <typename T, typename TResult>
bool IntegerCheck(char const * start, char const * stop, T x, TResult & out)
{
- if (errno != EINVAL && *stop == 0)
+ if (errno != EINVAL && *stop == 0 && start != stop)
{
out = static_cast<TResult>(x);
return static_cast<T>(out) == x;
@@ -80,7 +80,7 @@ bool to_uint64(char const * s, uint64_t & i)
#else
i = strtoull(s, &stop, 10);
#endif
- return *stop == 0;
+ return *stop == 0 && s != stop;
}
bool to_int64(char const * s, int64_t & i)
@@ -91,7 +91,7 @@ bool to_int64(char const * s, int64_t & i)
#else
i = strtoll(s, &stop, 10);
#endif
- return *stop == 0;
+ return *stop == 0 && s != stop;
}
bool to_double(char const * s, double & d)