# HG changeset patch # User Matti Hamalainen # Date 1578928374 -7200 # Node ID 308531ac74e75dcef81418a24fe90162e074e25e # Parent 31720ede4b50e888deb08ba1056c3e7890d9ca6e 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. diff -r 31720ede4b50 -r 308531ac74e7 th_printf.c --- 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;