printfing a number or string bigger than the field width should not crash.

This commit is contained in:
Andreas Kling 2018-10-31 22:40:10 +01:00
parent c7d5ce6b5a
commit a8f36f72a8
Notes: sideshowbarker 2024-07-19 18:35:31 +09:00

View file

@ -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)