]> git.sur5r.net Git - cc65/commitdiff
Fixed several bugs
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 16 Dec 2004 20:07:49 +0000 (20:07 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 16 Dec 2004 20:07:49 +0000 (20:07 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@3328 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/common/strbuf.c
src/common/xsprintf.c

index 12f7239b7699a479e9e6929ed27dca2376bce15e..6d1e262851368b2b01752e6d9e59ae0aa2c689c1 100644 (file)
@@ -342,7 +342,7 @@ void SB_VPrintf (StrBuf* S, const char* Format, va_list ap)
      * an allocation. If not, we have to reallocate and try again.
      */
     va_copy (tmp, ap);
      * an allocation. If not, we have to reallocate and try again.
      */
     va_copy (tmp, ap);
-    SizeNeeded = xvsnprintf (S->Buf, S->Allocated, Format, ap);
+    SizeNeeded = xvsnprintf (S->Buf, S->Allocated, Format, tmp);
     va_end (tmp);
 
     /* Check the result, the xvsnprintf function should not fail */
     va_end (tmp);
 
     /* Check the result, the xvsnprintf function should not fail */
index 8c7dc33eb0ac60c6f7a78712ade4835e6ede04b4..8ab92eccf457e7a5544d003484c5bec9316bc74b 100644 (file)
@@ -378,7 +378,7 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
         }
         /* Optional field width */
         if (F == '*') {
         }
         /* Optional field width */
         if (F == '*') {
-            P.Width = va_arg (ap, int);
+            P.Width = va_arg (P.ap, int);
             /* A negative field width argument is taken as a - flag followed
              * by a positive field width.
              */
             /* A negative field width argument is taken as a - flag followed
              * by a positive field width.
              */
@@ -405,13 +405,14 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
             F = *Format++;
             P.Flags |= fPrec;
             if (F == '*') {
             F = *Format++;
             P.Flags |= fPrec;
             if (F == '*') {
-                P.Prec = va_arg (ap, int);
+                P.Prec = va_arg (P.ap, int);
                 /* A negative precision argument is taken as if the precision
                  * were omitted.
                  */
                 if (P.Prec < 0) {
                     P.Flags &= ~fPrec;
                 }
                 /* A negative precision argument is taken as if the precision
                  * were omitted.
                  */
                 if (P.Prec < 0) {
                     P.Flags &= ~fPrec;
                 }
+                F = *Format++;          /* Skip the '*' */
             } else if (IsDigit (F)) {
                 P.Prec = F - '0';
                 while (1) {
             } else if (IsDigit (F)) {
                 P.Prec = F - '0';
                 while (1) {
@@ -425,8 +426,11 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
                 /* A negative precision argument is taken as if the precision
                  * were omitted.
                  */
                 /* A negative precision argument is taken as if the precision
                  * were omitted.
                  */
+                F = *Format++;          /* Skip the minus */
                 while (IsDigit (F = *Format++)) ;
                 P.Flags &= ~fPrec;
                 while (IsDigit (F = *Format++)) ;
                 P.Flags &= ~fPrec;
+            } else {
+                P.Prec = 0;
             }
         }
 
             }
         }
 
@@ -486,7 +490,7 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
         }
         /* If a precision is specified, the 0 flag is ignored */
         if (P.Flags & fPrec) {
         }
         /* If a precision is specified, the 0 flag is ignored */
         if (P.Flags & fPrec) {
-            P.Flags &= fZero;
+            P.Flags &= ~fZero;
         }
 
         /* Conversion specifier */
         }
 
         /* Conversion specifier */
@@ -519,13 +523,13 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
                 break;
 
             case 'c':
                 break;
 
             case 'c':
-                SBuf[0] = (char) va_arg (ap, int);
+                SBuf[0] = (char) va_arg (P.ap, int);
                 SBuf[1] = '\0';
                 FormatStr (&P, SBuf);
                 break;
 
             case 's':
                 SBuf[1] = '\0';
                 FormatStr (&P, SBuf);
                 break;
 
             case 's':
-                SPtr = va_arg (ap, const char*);
+                SPtr = va_arg (P.ap, const char*);
                 CHECK (SPtr != 0);
                 FormatStr (&P, SPtr);
                 break;
                 CHECK (SPtr != 0);
                 FormatStr (&P, SPtr);
                 break;