From: cuz Date: Thu, 16 Dec 2004 20:07:49 +0000 (+0000) Subject: Fixed several bugs X-Git-Tag: V2.12.0~508 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5b851fb62107e97845f600f91f90cb21107ab60f;p=cc65 Fixed several bugs git-svn-id: svn://svn.cc65.org/cc65/trunk@3328 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/common/strbuf.c b/src/common/strbuf.c index 12f7239b7..6d1e26285 100644 --- a/src/common/strbuf.c +++ b/src/common/strbuf.c @@ -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); - 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 */ diff --git a/src/common/xsprintf.c b/src/common/xsprintf.c index 8c7dc33eb..8ab92eccf 100644 --- a/src/common/xsprintf.c +++ b/src/common/xsprintf.c @@ -378,7 +378,7 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap) } /* 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. */ @@ -405,13 +405,14 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap) 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; } + F = *Format++; /* Skip the '*' */ } 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. */ + F = *Format++; /* Skip the minus */ 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) { - P.Flags &= fZero; + P.Flags &= ~fZero; } /* Conversion specifier */ @@ -519,13 +523,13 @@ int xvsnprintf (char* Buf, size_t Size, const char* Format, va_list ap) 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': - SPtr = va_arg (ap, const char*); + SPtr = va_arg (P.ap, const char*); CHECK (SPtr != 0); FormatStr (&P, SPtr); break;