Mercurial > hg > th-libs
diff th_printf.c @ 595:308531ac74e7
Fix internal printf() for case of NULL string pointer, but with format
precision shorter than 6 characters where "(null)" does not fit, return
empty string instead.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 13 Jan 2020 17:12:54 +0200 |
parents | ccff3eb8dbb6 |
children | 7f1efa37288b |
line wrap: on
line diff
--- a/th_printf.c Mon Jan 13 11:41:27 2020 +0200 +++ b/th_printf.c Mon Jan 13 17:12:54 2020 +0200 @@ -279,12 +279,19 @@ int th_vprintf_put_str(th_vprintf_ctx *ctx, th_vprintf_putch vputch, const char *str, int f_flags, const int f_width, const int f_prec) { - int nspacepad, f_len, ret = 0; + int nspacepad, f_len, ret; // Check for null strings if (str == NULL) + { + // If the "(null)" string does not fit precision, return empty + if (f_prec >= 0 && f_prec < 6) + return 0; + str = "(null)"; + } + // Compute padding etc f_len = strlen(str); if (f_prec >= 0 && f_len > f_prec) f_len = f_prec;