]> git.sur5r.net Git - cc65/commitdiff
Handling of the '+' and ' ' flags was incorrect if the value was negative
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 21 Oct 2000 21:52:21 +0000 (21:52 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 21 Oct 2000 21:52:21 +0000 (21:52 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@389 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/common/_printf.c

index b76f39a3b4e0ffa15f8ec0776f6fffc008a2ec75..40f2aace2ac89365d4b9c9342bf53bcb989288d4 100644 (file)
@@ -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;