From a8f36f72a89a451e3939c3aebe5fcedbd5540f11 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 31 Oct 2018 22:40:10 +0100 Subject: [PATCH] printfing a number or string bigger than the field width should not crash. --- AK/printf.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AK/printf.cpp b/AK/printf.cpp index 4bdc241fda..73d13594d0 100644 --- a/AK/printf.cpp +++ b/AK/printf.cpp @@ -49,7 +49,7 @@ ALWAYS_INLINE int printNumber(PutChFunc putch, char*& bufptr, dword number, bool } size_t numlen = p - buf; - if (!fieldWidth) + if (!fieldWidth || fieldWidth < numlen) fieldWidth = numlen; if (!leftPad) { for (unsigned i = 0; i < fieldWidth - numlen; ++i) { @@ -72,7 +72,7 @@ template ALWAYS_INLINE int printString(PutChFunc putch, char*& bufptr, const char* str, bool leftPad, dword fieldWidth) { size_t len = strlen(str); - if (!fieldWidth) + if (!fieldWidth || fieldWidth < len) fieldWidth = len; if (!leftPad) { for (unsigned i = 0; i < fieldWidth - len; ++i)