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:
authorAlex Zolotarev <alex@maps.me>2016-03-16 14:11:37 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-03-23 16:56:30 +0300
commit4a2c4cfddeb2a2c10a7a1013a8c87175c079b6eb (patch)
tree47de9cbf2478541d0499ff6d61fcc818279b3a1c /base
parent84f9751b6f415207ae02a42ab5690098dda030e3 (diff)
strings::to_double now checks for finite values and overflows.
Diffstat (limited to 'base')
-rw-r--r--base/base_tests/string_utils_test.cpp4
-rw-r--r--base/string_utils.cpp2
2 files changed, 5 insertions, 1 deletions
diff --git a/base/base_tests/string_utils_test.cpp b/base/base_tests/string_utils_test.cpp
index 1c22d9df55..3f6dc94418 100644
--- a/base/base_tests/string_utils_test.cpp
+++ b/base/base_tests/string_utils_test.cpp
@@ -165,6 +165,10 @@ UNIT_TEST(to_double)
s = "123.456 we don't parse it.";
TEST(!strings::to_double(s, d), ());
+
+ TEST(!strings::to_double("INF", d), ());
+ TEST(!strings::to_double("NAN", d), ());
+ TEST(!strings::to_double("1.18973e+4932", d), ());
}
UNIT_TEST(to_int)
diff --git a/base/string_utils.cpp b/base/string_utils.cpp
index 30a619dd13..effab2849f 100644
--- a/base/string_utils.cpp
+++ b/base/string_utils.cpp
@@ -80,7 +80,7 @@ bool to_double(char const * s, double & d)
{
char * stop;
d = strtod(s, &stop);
- return *stop == 0 && s != stop;
+ return *stop == 0 && s != stop && isfinite(d);
}
UniString MakeLowerCase(UniString const & s)