From 673472cbdc20466c1112e380a23cbe4460e57de6 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 9 Jan 2023 04:22:13 +0100 Subject: [PATCH] Fix error --- src/Parsers/ExpressionElementParsers.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Parsers/ExpressionElementParsers.cpp b/src/Parsers/ExpressionElementParsers.cpp index 23f016b7791..2fb0d928dfd 100644 --- a/src/Parsers/ExpressionElementParsers.cpp +++ b/src/Parsers/ExpressionElementParsers.cpp @@ -1,8 +1,9 @@ +#include +#include #include #include #include -#include #include #include @@ -828,9 +829,12 @@ bool ParserNumber::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) auto try_read_float = [&](const char * it, const char * end) { - Float64 float_value = 0; - ReadBufferFromMemory buf(it, end - it); - if (tryReadFloatTextPrecise(float_value, buf)) + std::string buf(it, end); /// Copying is needed to ensure the string is 0-terminated. + char * str_end; + errno = 0; /// Functions strto* don't clear errno. + /// The usage of strtod is needed, because we parse hex floating point literals as well. + Float64 float_value = std::strtod(buf.c_str(), &str_end); + if (str_end == buf.c_str() + buf.size() && errno != ERANGE) { if (float_value < 0) throw Exception("Logical error: token number cannot begin with minus, but parsed float number is less than zero.", ErrorCodes::LOGICAL_ERROR);