diff options
author | Simon Glass <sjg@chromium.org> | 2024-09-20 09:24:29 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2024-10-03 11:52:16 -0600 |
commit | e2d96ac9ee9f81c8f72435bff55f924d27ad92d1 (patch) | |
tree | a23cadbf9a98f9a2659296e00188e39acabff964 /lib/tiny-printf.c | |
parent | eb08abc2936cb545ecc814214d499136e68c2658 (diff) |
tiny-printf: Correct return values
The sprintf() etc. functions are supposed to return the length of the
string written, but do not. Fix this by checking the amount of buffer
space used.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/tiny-printf.c')
-rw-r--r-- | lib/tiny-printf.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c index 9a70c6095b3..64dee779c4a 100644 --- a/lib/tiny-printf.c +++ b/lib/tiny-printf.c @@ -365,16 +365,15 @@ int sprintf(char *buf, const char *fmt, ...) { struct printf_info info; va_list va; - int ret; va_start(va, fmt); info.outstr = buf; info.putc = putc_outstr; - ret = _vprintf(&info, fmt, va); + _vprintf(&info, fmt, va); va_end(va); *info.outstr = '\0'; - return ret; + return info.outstr - buf; } #if CONFIG_IS_ENABLED(LOG) @@ -382,14 +381,13 @@ int sprintf(char *buf, const char *fmt, ...) int vsnprintf(char *buf, size_t size, const char *fmt, va_list va) { struct printf_info info; - int ret; info.outstr = buf; info.putc = putc_outstr; - ret = _vprintf(&info, fmt, va); + _vprintf(&info, fmt, va); *info.outstr = '\0'; - return ret; + return info.outstr - buf; } #endif @@ -398,16 +396,15 @@ int snprintf(char *buf, size_t size, const char *fmt, ...) { struct printf_info info; va_list va; - int ret; va_start(va, fmt); info.outstr = buf; info.putc = putc_outstr; - ret = _vprintf(&info, fmt, va); + _vprintf(&info, fmt, va); va_end(va); *info.outstr = '\0'; - return ret; + return info.outstr - buf; } void print_grouped_ull(unsigned long long int_val, int digits) |