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:
+14
-5
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user