From af4df7932a391219acfa9f8941e37f26746c7079 Mon Sep 17 00:00:00 2001 From: Vitaly Stoyan Date: Tue, 29 Oct 2024 12:09:38 +0300 Subject: [PATCH] better --- ydb/library/yql/public/decimal/ut/yql_decimal_ut.cpp | 2 ++ ydb/library/yql/public/decimal/yql_decimal.cpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ydb/library/yql/public/decimal/ut/yql_decimal_ut.cpp b/ydb/library/yql/public/decimal/ut/yql_decimal_ut.cpp index cb120281a24c..996bd48257b7 100644 --- a/ydb/library/yql/public/decimal/ut/yql_decimal_ut.cpp +++ b/ydb/library/yql/public/decimal/ut/yql_decimal_ut.cpp @@ -228,6 +228,8 @@ Y_UNIT_TEST_SUITE(TYqlDecimalTest) { UNIT_ASSERT(IsError(FromStringEx("E2", 35, 15))); // empty UNIT_ASSERT(IsError(FromStringEx("E2E4", 35, 15))); // empty UNIT_ASSERT(IsError(FromStringEx("NANE5", 35, 15))); // nan with exp + UNIT_ASSERT(IsError(FromStringEx("2.1E0X", 35, 2))); // not fully parsed exp + UNIT_ASSERT(IsError(FromStringEx("2.1E+-1", 35, 2))); // two signs } Y_UNIT_TEST(TestSpecialAsString) { diff --git a/ydb/library/yql/public/decimal/yql_decimal.cpp b/ydb/library/yql/public/decimal/yql_decimal.cpp index c6e0995aabc1..6be5c19167ed 100644 --- a/ydb/library/yql/public/decimal/yql_decimal.cpp +++ b/ydb/library/yql/public/decimal/yql_decimal.cpp @@ -223,10 +223,13 @@ TInt128 FromStringEx(const TStringBuf& str, ui8 precision, ui8 scale) { ++ptr; if (ptr != s + str.size() && *ptr == '+') { ++ptr; + if (ptr != s + str.size() && *ptr == '-') + return Err(); } int exp; - if (std::from_chars(ptr, s + str.size(), exp).ec != std::errc()) + auto [finish, ec] = std::from_chars(ptr, s + str.size(), exp); + if (ec != std::errc() || finish != s + str.size()) return Err(); const int p = precision, s = int(scale) + exp;