1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-08 06:25:17 +00:00

Fixed several bugs

git-svn-id: svn://svn.cc65.org/cc65/trunk@3328 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2004-12-16 20:07:49 +00:00
parent e43766ea93
commit 5b851fb621
2 changed files with 10 additions and 6 deletions

View 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. * an allocation. If not, we have to reallocate and try again.
*/ */
va_copy (tmp, ap); va_copy (tmp, ap);
SizeNeeded = xvsnprintf (S->Buf, S->Allocated, Format, ap); SizeNeeded = xvsnprintf (S->Buf, S->Allocated, Format, tmp);
va_end (tmp); va_end (tmp);
/* Check the result, the xvsnprintf function should not fail */ /* Check the result, the xvsnprintf function should not fail */

View File

@@ -378,7 +378,7 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
} }
/* Optional field width */ /* Optional field width */
if (F == '*') { 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 /* A negative field width argument is taken as a - flag followed
* by a positive field width. * by a positive field width.
*/ */
@@ -405,13 +405,14 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap)
F = *Format++; F = *Format++;
P.Flags |= fPrec; P.Flags |= fPrec;
if (F == '*') { 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 /* A negative precision argument is taken as if the precision
* were omitted. * were omitted.
*/ */
if (P.Prec < 0) { if (P.Prec < 0) {
P.Flags &= ~fPrec; P.Flags &= ~fPrec;
} }
F = *Format++; /* Skip the '*' */
} else if (IsDigit (F)) { } else if (IsDigit (F)) {
P.Prec = F - '0'; P.Prec = F - '0';
while (1) { 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 /* A negative precision argument is taken as if the precision
* were omitted. * were omitted.
*/ */
F = *Format++; /* Skip the minus */
while (IsDigit (F = *Format++)) ; while (IsDigit (F = *Format++)) ;
P.Flags &= ~fPrec; 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 a precision is specified, the 0 flag is ignored */
if (P.Flags & fPrec) { 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; break;
case 'c': case 'c':
SBuf[0] = (char) va_arg (ap, int); SBuf[0] = (char) va_arg (P.ap, int);
SBuf[1] = '\0'; SBuf[1] = '\0';
FormatStr (&P, SBuf); FormatStr (&P, SBuf);
break; break;
case 's': case 's':
SPtr = va_arg (ap, const char*); SPtr = va_arg (P.ap, const char*);
CHECK (SPtr != 0); CHECK (SPtr != 0);
FormatStr (&P, SPtr); FormatStr (&P, SPtr);
break; break;