From 3b7f8eeaabb87f10481442309b0a5bf514fab651 Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 21 Oct 2000 21:52:21 +0000 Subject: [PATCH] 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 --- libsrc/common/_printf.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) 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; -- 2.39.5