From 9053dbbf62c7c9f4723959b557078a787ba6afec Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Jul 2021 14:51:17 +0200 Subject: msnprintf: return number of printed characters excluding null byte ... even when the output is "capped" by the maximum length argument. Clarified in the docs. Closes #7361 --- lib/mprintf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/mprintf.c') diff --git a/lib/mprintf.c b/lib/mprintf.c index 529202686..7a1aec570 100644 --- a/lib/mprintf.c +++ b/lib/mprintf.c @@ -1017,9 +1017,11 @@ int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format, retcode = dprintf_formatf(&info, addbyter, format, ap_save); if((retcode != -1) && info.max) { /* we terminate this with a zero byte */ - if(info.max == info.length) + if(info.max == info.length) { /* we're at maximum, scrap the last letter */ info.buffer[-1] = 0; + retcode--; /* don't count the nul byte */ + } else info.buffer[0] = 0; } -- cgit v1.2.1