From adde2e5b4bdb3739b37535b9db069238fc3628da Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Tue, 6 Jun 2023 09:32:33 -0400 Subject: [PATCH] roken: snprintf properly account for char widths If a char width is specified the number of output buffer bytes consumed might be greater than one. Update append_char() to return the number of bytes consumed and use that value in xyzprintf() instead of one. --- lib/roken/snprintf.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/roken/snprintf.c b/lib/roken/snprintf.c index 0b99a4b6f..54018bae7 100644 --- a/lib/roken/snprintf.c +++ b/lib/roken/snprintf.c @@ -309,7 +309,7 @@ append_char(struct snprintf_state *state, (*state->append_char) (state, ' '); ++len; } - return 0; + return len; } /* @@ -437,8 +437,7 @@ xyzprintf (struct snprintf_state *state, const char *char_format, va_list ap) switch (c) { case 'c' : - append_char(state, va_arg(ap, int), width, flags); - ++len; + len += append_char(state, va_arg(ap, int), width, flags); break; case 's' : len += append_string(state,