Fixed when the int value of "%0[width]d" is negative, the minus sign should be formatted before the padding '0' (#2329)

This commit is contained in:
F1F88
2025-11-08 16:33:30 +00:00
committed by GitHub
parent 22cc68808c
commit 2ae0d05a23
+14 -5
View File
@@ -491,13 +491,15 @@ void AddInt(char **buf_p, size_t &maxlen, int val, int width, int flags)
unsignedVal /= 10;
} while (unsignedVal);
if (signedVal < 0)
{
text[digits++] = '-';
}
buf = *buf_p;
// minus sign BEFORE left padding if padding with zeros
if (signedVal < 0 && maxlen && (flags & ZEROPAD))
{
*buf++ = '-';
maxlen--;
}
if (!(flags & LADJUST))
{
while ((digits < width) && maxlen)
@@ -508,6 +510,13 @@ void AddInt(char **buf_p, size_t &maxlen, int val, int width, int flags)
}
}
// minus sign AFTER left padding if padding with spaces
if (signedVal < 0 && maxlen && !(flags & ZEROPAD))
{
*buf++ = '-';
maxlen--;
}
while (digits-- && maxlen)
{
*buf++ = text[digits];