From b5e077c6f74762e73593b2fc796de85a1cf312a8 Mon Sep 17 00:00:00 2001 From: F1F88 <0xf1f88@gmail.com> Date: Tue, 4 Feb 2025 09:37:31 +0800 Subject: [PATCH] Fix formatting error when left-aligned and width is less than the number of characters (#2221) (#2255) --- core/logic/sprintf.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/logic/sprintf.cpp b/core/logic/sprintf.cpp index 93736318..6263ddfb 100644 --- a/core/logic/sprintf.cpp +++ b/core/logic/sprintf.cpp @@ -405,7 +405,7 @@ void AddBinary(char **buf_p, size_t &maxlen, unsigned int val, int width, int fl if (flags & LADJUST) { - while (width-- && maxlen) + while ((width-- > 0) && maxlen) { *buf++ = (flags & ZEROPAD) ? '0' : ' '; maxlen--; @@ -449,7 +449,7 @@ void AddUInt(char **buf_p, size_t &maxlen, unsigned int val, int width, int flag if (flags & LADJUST) { - while (width-- && maxlen) + while ((width-- > 0) && maxlen) { *buf++ = (flags & ZEROPAD) ? '0' : ' '; maxlen--; @@ -511,7 +511,7 @@ void AddInt(char **buf_p, size_t &maxlen, int val, int width, int flags) if (flags & LADJUST) { - while (width-- && maxlen) + while ((width-- > 0) && maxlen) { *buf++ = (flags & ZEROPAD) ? '0' : ' '; maxlen--; @@ -572,7 +572,7 @@ void AddHex(char **buf_p, size_t &maxlen, unsigned int val, int width, int flags if (flags & LADJUST) { - while (width-- && maxlen) + while ((width-- > 0) && maxlen) { *buf++ = (flags & ZEROPAD) ? '0' : ' '; maxlen--;