Skip to content

Commit d88299d

Browse files
committed
Adding fix for is_integer overflow.
This should avoid using unnecessarily sized unsigned types, while also avoiding overflow.
1 parent ee79fe6 commit d88299d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

include/fast_float/ascii_number.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,20 @@ template <typename UC> fastfloat_really_inline constexpr bool has_simd_opt() {
2828
#endif
2929
}
3030

31+
template <typename value_type> struct get_equal_sized_uint {
32+
using type = std::conditional_t<
33+
sizeof(value_type) == 4, uint32_t,
34+
std::conditional_t<sizeof(value_type) == 2, uint16_t, uint8_t>>;
35+
};
36+
37+
template <typename value_type>
38+
using get_equal_sized_uint_t = typename get_equal_sized_uint<value_type>::type;
39+
3140
// Next function can be micro-optimized, but compilers are entirely
3241
// able to optimize it well.
3342
template <typename UC>
3443
fastfloat_really_inline constexpr bool is_integer(UC c) noexcept {
35-
return static_cast<uint8_t>(c - UC('0')) < 10;
44+
return static_cast<get_equal_sized_uint_t<UC>>(c - UC('0')) < 10;
3645
}
3746

3847
fastfloat_really_inline constexpr uint64_t byteswap(uint64_t val) {

0 commit comments

Comments
 (0)