From: cuz Date: Sat, 21 Oct 2000 21:52:21 +0000 (+0000) Subject: Handling of the '+' and ' ' flags was incorrect if the value was negative X-Git-Tag: V2.12.0~3137 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3b7f8eeaabb87f10481442309b0a5bf514fab651;p=cc65 Handling of the '+' and ' ' flags was incorrect if the value was negative git-svn-id: svn://svn.cc65.org/cc65/trunk@389 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/libsrc/common/_printf.c b/libsrc/common/_printf.c index b76f39a3b..40f2aace2 100644 --- a/libsrc/common/_printf.c +++ b/libsrc/common/_printf.c @@ -148,15 +148,26 @@ flags_done: case 'd': case 'i': - if (addsign) { - *s++ = '+'; - } else if (addblank) { - *s++ = ' '; - } - if (islong) { - ltoa (va_arg (ap, long), s, 10); - } else { - itoa (va_arg (ap, int), s, 10); + if (islong) { + l = va_arg (ap, long); + if (l >= 0) { + if (addsign) { + *s++ = '+'; + } else if (addblank) { + *s++ = ' '; + } + } + ltoa (l, s, 10); + } else { + i = va_arg (ap, int); + if (i >= 0) { + if (addsign) { + *s++ = '+'; + } else if (addblank) { + *s++ = ' '; + } + } + itoa (i, s, 10); } break;