From 0ce95ffe6ac9cb0ab59cce5d9f22a1c9dd630144 Mon Sep 17 00:00:00 2001
From: cuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Date: Thu, 16 Dec 2004 20:26:46 +0000
Subject: [PATCH] Fixed another bug

git-svn-id: svn://svn.cc65.org/cc65/trunk@3329 b7a2c559-68d2-44c3-8de9-860c34a00d81
---
 src/common/xsprintf.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/common/xsprintf.c b/src/common/xsprintf.c
index 8ab92eccf..0242542f7 100644
--- a/src/common/xsprintf.c
+++ b/src/common/xsprintf.c
@@ -211,6 +211,15 @@ static void FormatInt (PrintfCtrl* P, unsigned long Val)
     /* Convert the value into a (reversed string). */
     ToStr (P, Val);
 
+    /* The default precision for all integer conversions is one. This means
+     * that the fPrec flag is always set and does not need to be checked 
+     * later on.
+     */
+    if ((P->Flags & fPrec) == 0) {
+        P->Flags |= fPrec;
+        P->Prec = 1;
+    }
+
     /* Determine the leaders for alternative forms */
     if ((P->Flags & fHash) != 0) {
         if (P->Base == 16) {
@@ -219,14 +228,14 @@ static void FormatInt (PrintfCtrl* P, unsigned long Val)
             Lead[LeadCount++] = (P->Flags & fUpcase)? 'X' : 'x';
         } else if (P->Base == 8) {
             /* Alternative form for 'o': always add a leading zero. */
-            if ((P->Flags & fPrec) == 0 || P->Prec <= P->ArgLen) {
+            if (P->Prec <= P->ArgLen) {
                 Lead[LeadCount++] = '0';
             }
         }
     }
 
     /* Determine the amount of precision padding needed */
-    if ((P->Flags & fPrec) != 0 && P->ArgLen < P->Prec) {
+    if (P->ArgLen < P->Prec) {
         PrecPadding = P->Prec - P->ArgLen;
     } else {
         PrecPadding = 0;