1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:47:45 +00:00

AK: Fix printf("%c", 0)

It was me who has broken this, sorry ;(
This commit is contained in:
Sergey Bugaev 2020-06-04 22:43:51 +03:00 committed by Andreas Kling
parent 71da52482c
commit 9e046bcef1

View file

@ -251,9 +251,8 @@ ALWAYS_INLINE int print_octal_number(PutChFunc putch, char*& bufptr, u32 number,
} }
template<typename PutChFunc> template<typename PutChFunc>
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)) if (!dot && (!field_width || field_width < len))
field_width = len; field_width = len;
size_t pad_amount = field_width > len ? field_width - len : 0; 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) { switch (*p) {
case 's': { case 's': {
const char* sp = va_arg(ap, const char*); 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; } break;
case 'd': case 'd':
@ -417,8 +418,8 @@ ALWAYS_INLINE int printf_internal(PutChFunc putch, char* buffer, const char*& fm
break; break;
case 'c': { case 'c': {
char s[2] { (char)va_arg(ap, int), 0 }; char c = va_arg(ap, int);
ret += print_string(putch, bufptr, s, left_pad, field_width, dot); ret += print_string(putch, bufptr, &c, 1, left_pad, field_width, dot);
} break; } break;
case '%': case '%':