diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-10-31 22:40:10 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-10-31 22:40:10 +0100 |
commit | a8f36f72a89a451e3939c3aebe5fcedbd5540f11 (patch) | |
tree | ed537a87a300784dae39900850f41b6a3a36ccef /AK/printf.cpp | |
parent | c7d5ce6b5a2b031d8fe5d319f158d91be66ca998 (diff) | |
download | serenity-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.cpp | 4 |
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) |