From fd4f214e4310cbff2b7caa8c09223344bdd3bc0d Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 5 May 2021 23:04:15 +0300 Subject: [PATCH] Fix error --- base/common/itoa.h | 12 +++++++----- src/IO/WriteHelpers.h | 4 +--- src/IO/WriteIntText.h | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/base/common/itoa.h b/base/common/itoa.h index 1a533b9b397..4c86239de36 100644 --- a/base/common/itoa.h +++ b/base/common/itoa.h @@ -105,7 +105,7 @@ using UnsignedOfSize = typename SelectType uint16_t, uint32_t, uint64_t, - UInt128 + __uint128_t >::Result; /// Holds the result of dividing an unsigned N-byte variable by 10^N resulting in @@ -349,6 +349,8 @@ static inline int digits10(T x) template static inline char * writeUIntText(T x, char * p) { + static_assert(is_unsigned_v); + int len = digits10(x); auto pp = p + len; while (x >= 100) @@ -418,25 +420,25 @@ inline char * itoa(char8_t i, char * p) } template <> -inline char * itoa(UInt128 i, char * p) +inline char * itoa(UInt128 i, char * p) { return impl::writeUIntText(i, p); } template <> -inline char * itoa(Int128 i, char * p) +inline char * itoa(Int128 i, char * p) { return impl::writeSIntText(i, p); } template <> -inline char * itoa(UInt256 i, char * p) +inline char * itoa(UInt256 i, char * p) { return impl::writeUIntText(i, p); } template <> -inline char * itoa(Int256 i, char * p) +inline char * itoa(Int256 i, char * p) { return impl::writeSIntText(i, p); } diff --git a/src/IO/WriteHelpers.h b/src/IO/WriteHelpers.h index 5b2e3a8339d..7efc8afcb32 100644 --- a/src/IO/WriteHelpers.h +++ b/src/IO/WriteHelpers.h @@ -905,13 +905,11 @@ String decimalFractional(const T & x, UInt32 scale) { if constexpr (std::is_same_v) { - static constexpr Int128 max_int128 = (Int128(0x7fffffffffffffffll) << 64) + 0xffffffffffffffffll; - if (x <= std::numeric_limits::max()) return decimalFractional(static_cast(x), scale); else if (x <= std::numeric_limits::max()) return decimalFractional(static_cast(x), scale); - else if (x <= max_int128) + else if (x <= std::numeric_limits::max()) return decimalFractional(static_cast(x), scale); } else if constexpr (std::is_same_v) diff --git a/src/IO/WriteIntText.h b/src/IO/WriteIntText.h index 9a85373ef5a..456aed350fc 100644 --- a/src/IO/WriteIntText.h +++ b/src/IO/WriteIntText.h @@ -32,8 +32,8 @@ namespace detail void NO_INLINE writeUIntTextFallback(T x, WriteBuffer & buf) { char tmp[max_int_width]; - int len = itoa(x, tmp) - tmp; - buf.write(tmp, len); + char * end = itoa(x, tmp); + buf.write(tmp, end - tmp); } }