diff --git a/core/logic/sprintf.cpp b/core/logic/sprintf.cpp index b872194f7..703ee4b66 100644 --- a/core/logic/sprintf.cpp +++ b/core/logic/sprintf.cpp @@ -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];