From 4666b4e7371659b22fc09dd2ec23bb7ffde283a8 Mon Sep 17 00:00:00 2001 From: Andreas Tsouchlos Date: Sun, 13 Feb 2022 21:57:43 +0100 Subject: [PATCH] Added proper error handling for too long ints --- const_fmt/format_impl.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/const_fmt/format_impl.h b/const_fmt/format_impl.h index 412e2db..3cb9af1 100644 --- a/const_fmt/format_impl.h +++ b/const_fmt/format_impl.h @@ -89,7 +89,12 @@ constexpr inline void copy2(char* dst, const char* src) { template constexpr inline void format_decimal(char* out, uint_t value, int n_digits, int size) { - if (n_digits > size) return; + if (n_digits > size) { + for (int i = 0; i < size; ++i) { + *(out++) = 'f'; + } + return; + } out += size; while (value >= 100) { @@ -149,7 +154,7 @@ constexpr inline void format_int(char* out, int_t value) { template constexpr inline void format_float(char* out, float_t value) { - *(out) = 'f'; + *(out) = 'f'; *(out + t_fmt_node.length - t_fmt_node.precision - 1) = '.'; }