From a4ec86c8ae39459562260e22be2cafe34ac5f3e6 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Thu, 7 Jan 2016 19:54:52 +0300 Subject: [PATCH] =?UTF-8?q?Fixed=20bug=20when=20strings::to=5Fdouble(?= =?UTF-8?q?=E2=80=9C=E2=80=9D,=20d)=20incorrectly=20returned=20true.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/base_tests/string_utils_test.cpp | 6 ++++++ base/string_utils.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/base/base_tests/string_utils_test.cpp b/base/base_tests/string_utils_test.cpp index bd54fcaef3..9342daf3e0 100644 --- a/base/base_tests/string_utils_test.cpp +++ b/base/base_tests/string_utils_test.cpp @@ -137,6 +137,9 @@ UNIT_TEST(to_double) string s; double d; + s = ""; + TEST(!strings::to_double(s, d), ()); + s = "0.123"; TEST(strings::to_double(s, d), ()); TEST_ALMOST_EQUAL_ULPS(0.123, d, ()); @@ -159,6 +162,9 @@ UNIT_TEST(to_double) s = "labuda"; TEST(!strings::to_double(s, d), ()); + + s = "123.456 we don't parse it."; + TEST(!strings::to_double(s, d), ()); } UNIT_TEST(to_int) diff --git a/base/string_utils.cpp b/base/string_utils.cpp index 971817ba99..a9b59425e4 100644 --- a/base/string_utils.cpp +++ b/base/string_utils.cpp @@ -81,7 +81,7 @@ bool to_double(char const * s, double & d) { char * stop; d = strtod(s, &stop); - return stop && *stop == 0; + return stop && *stop == 0 && s != stop; } UniString MakeLowerCase(UniString const & s)