summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@serenityos.org>2020-06-04 22:43:51 +0300
committerAndreas Kling <kling@serenityos.org>2020-06-06 14:42:31 +0200
commit9e046bcef1a8e65a7e0c43e570f07ea2e661da2d (patch)
tree9f0b80c0343e619a5d152ed34e36988918c6e3e8 /AK
parent71da52482c0b190898805bc20b3b0e138d8ad258 (diff)
downloadserenity-9e046bcef1a8e65a7e0c43e570f07ea2e661da2d.zip
AK: Fix printf("%c", 0)
It was me who has broken this, sorry ;(
Diffstat (limited to 'AK')
-rw-r--r--AK/PrintfImplementation.h11
1 files 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<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))
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 '%':