From 9e046bcef1a8e65a7e0c43e570f07ea2e661da2d Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Thu, 4 Jun 2020 22:43:51 +0300 Subject: [PATCH] AK: Fix printf("%c", 0) It was me who has broken this, sorry ;( --- AK/PrintfImplementation.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/AK/PrintfImplementation.h b/AK/PrintfImplementation.h index 1f9966e22e..6f1b45d025 100644 --- a/AK/PrintfImplementation.h +++ b/AK/PrintfImplementation.h @@ -251,9 +251,8 @@ ALWAYS_INLINE int print_octal_number(PutChFunc putch, char*& bufptr, u32 number, } template -ALWAYS_INLINE int print_string(PutChFunc putch, char*& bufptr, const char* str, bool left_pad, size_t field_width, bool dot) +ALWAYS_INLINE int print_string(PutChFunc putch, char*& bufptr, const char* str, size_t len, bool left_pad, size_t field_width, bool dot) { - size_t len = strlen(str); if (!dot && (!field_width || field_width < len)) field_width = len; size_t pad_amount = field_width > len ? field_width - len : 0; @@ -362,7 +361,9 @@ ALWAYS_INLINE int printf_internal(PutChFunc putch, char* buffer, const char*& fm switch (*p) { case 's': { const char* sp = va_arg(ap, const char*); - ret += print_string(putch, bufptr, sp ? sp : "(null)", left_pad, field_width, dot); + if (!sp) + sp = "(null)"; + ret += print_string(putch, bufptr, sp, strlen(sp), left_pad, field_width, dot); } break; case 'd': @@ -417,8 +418,8 @@ ALWAYS_INLINE int printf_internal(PutChFunc putch, char* buffer, const char*& fm break; case 'c': { - char s[2] { (char)va_arg(ap, int), 0 }; - ret += print_string(putch, bufptr, s, left_pad, field_width, dot); + char c = va_arg(ap, int); + ret += print_string(putch, bufptr, &c, 1, left_pad, field_width, dot); } break; case '%':