diff options
author | Daniel Stenberg <daniel@haxx.se> | 2021-07-07 14:51:17 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2021-07-08 10:05:39 +0200 |
commit | 9053dbbf62c7c9f4723959b557078a787ba6afec (patch) | |
tree | a6f859428ac17f47bd89e2dd72b5b11220525699 /lib/mprintf.c | |
parent | e7416cfd2bd58d256b8524f31ef22a43aa23a970 (diff) | |
download | curl-9053dbbf62c7c9f4723959b557078a787ba6afec.tar.gz |
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
Diffstat (limited to 'lib/mprintf.c')
-rw-r--r-- | lib/mprintf.c | 4 |
1 files changed, 3 insertions, 1 deletions
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; } |