summaryrefslogtreecommitdiff
path: root/AK/printf.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-10-31 22:40:10 +0100
committerAndreas Kling <awesomekling@gmail.com>2018-10-31 22:40:10 +0100
commita8f36f72a89a451e3939c3aebe5fcedbd5540f11 (patch)
treeed537a87a300784dae39900850f41b6a3a36ccef /AK/printf.cpp
parentc7d5ce6b5a2b031d8fe5d319f158d91be66ca998 (diff)
downloadserenity-a8f36f72a89a451e3939c3aebe5fcedbd5540f11.zip
printfing a number or string bigger than the field width should not crash.
Diffstat (limited to 'AK/printf.cpp')
-rw-r--r--AK/printf.cpp4
1 files 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<typename PutChFunc>
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)