From 4a2c4cfddeb2a2c10a7a1013a8c87175c079b6eb Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Wed, 16 Mar 2016 14:11:37 +0300 Subject: [PATCH] strings::to_double now checks for finite values and overflows. --- base/base_tests/string_utils_test.cpp | 4 ++++ base/string_utils.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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)