Skip to content

Commit a8f36f7

Browse files
committed
printfing a number or string bigger than the field width should not crash.
1 parent c7d5ce6 commit a8f36f7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

AK/printf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ALWAYS_INLINE int printNumber(PutChFunc putch, char*& bufptr, dword number, bool
4949
}
5050

5151
size_t numlen = p - buf;
52-
if (!fieldWidth)
52+
if (!fieldWidth || fieldWidth < numlen)
5353
fieldWidth = numlen;
5454
if (!leftPad) {
5555
for (unsigned i = 0; i < fieldWidth - numlen; ++i) {
@@ -72,7 +72,7 @@ template<typename PutChFunc>
7272
ALWAYS_INLINE int printString(PutChFunc putch, char*& bufptr, const char* str, bool leftPad, dword fieldWidth)
7373
{
7474
size_t len = strlen(str);
75-
if (!fieldWidth)
75+
if (!fieldWidth || fieldWidth < len)
7676
fieldWidth = len;
7777
if (!leftPad) {
7878
for (unsigned i = 0; i < fieldWidth - len; ++i)

0 commit comments

Comments
 (0)