From d88299dd4c3fe84a1a44af2afc4eb09669224db5 Mon Sep 17 00:00:00 2001 From: RealTimeChris <40668522+RealTimeChris@users.noreply.github.com> Date: Wed, 27 Nov 2024 07:41:08 -0500 Subject: [PATCH] Adding fix for is_integer overflow. This should avoid using unnecessarily sized unsigned types, while also avoiding overflow. --- include/fast_float/ascii_number.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/fast_float/ascii_number.h b/include/fast_float/ascii_number.h index 9b5befe..a70db6e 100644 --- a/include/fast_float/ascii_number.h +++ b/include/fast_float/ascii_number.h @@ -28,11 +28,20 @@ template fastfloat_really_inline constexpr bool has_simd_opt() { #endif } +template struct get_equal_sized_uint { + using type = std::conditional_t< + sizeof(value_type) == 4, uint32_t, + std::conditional_t>; +}; + +template +using get_equal_sized_uint_t = typename get_equal_sized_uint::type; + // Next function can be micro-optimized, but compilers are entirely // able to optimize it well. template fastfloat_really_inline constexpr bool is_integer(UC c) noexcept { - return static_cast(c - UC('0')) < 10; + return static_cast>(c - UC('0')) < 10; } fastfloat_really_inline constexpr uint64_t byteswap(uint64_t val) {