From b0a74f162e1cb7db9dd6a8fbaed9bfbf8ae17a10 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 5 Nov 2020 22:51:28 +0100 Subject: [PATCH] Fix string_printf in case of error in formating. --- m-string.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/m-string.h b/m-string.h index d76a08b8..b36677cb 100644 --- a/m-string.h +++ b/m-string.h @@ -792,8 +792,12 @@ string_printf (string_t v, const char format[], ...) size = vsnprintf (ptr, alloc, format, args); M_ASSERT (size > 0 && (size_t)size < alloc); } - if (size >= 0) { + if (M_LIKELY (size >= 0)) { stringi_set_size(v, (size_t) size); + } else { + // An error occured during the conversion: Assign an empty string. + stringi_set_size(v, 0); + ptr[0] = 0; } va_end (args); STRINGI_CONTRACT (v); @@ -1411,7 +1415,7 @@ string_it(string_it_t it, const string_t str) } /* Set the iterator to the end of string - The iterator references therefore nothong. + The iterator references therefore nothing. */ static inline void string_it_end(string_it_t it, const string_t str)