6262 * causing nasty effects.
6363 **************************************************************/
6464
65- /*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.26 2005/03/20 13:54:53 momjian Exp $";*/
65+ /*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.27 2005/04/14 20:53:09 tgl Exp $";*/
6666
6767static void dopr (char * buffer ,const char * format ,va_list args ,char * end );
6868
@@ -194,7 +194,7 @@ dopr(char *buffer, const char *format, va_list args, char *end)
194194int precision ;
195195int position ;
196196char * output ;
197- int percents = 1 ;
197+ int nargs = 1 ;
198198const char * p ;
199199struct fmtpar
200200{
@@ -220,18 +220,22 @@ dopr(char *buffer, const char *format, va_list args, char *end)
220220int longlongflag ;
221221}* fmtpar ,* * fmtparptr ;
222222
223- /* Create enough structures to hold all arguments */
223+ /*
224+ * Create enough structures to hold all arguments. This overcounts,
225+ * eg not all '*' characters are necessarily arguments, but it's not
226+ * worth being exact.
227+ */
224228for (p = format ;* p != '\0' ;p ++ )
225- if (* p == '%' ) /* counts %% as two, so overcounts */
226- percents ++ ;
229+ if (* p == '%' || * p == '*' )
230+ nargs ++ ;
227231
228232/* Need to use malloc() because memory system might not be started yet. */
229- if ((fmtpar = malloc (sizeof (struct fmtpar )* percents ))== NULL )
233+ if ((fmtpar = malloc (sizeof (struct fmtpar )* nargs ))== NULL )
230234{
231235fprintf (stderr ,_ ("out of memory\n" ));
232236exit (1 );
233237}
234- if ((fmtparptr = malloc (sizeof (struct fmtpar * )* percents ))== NULL )
238+ if ((fmtparptr = malloc (sizeof (struct fmtpar * )* nargs ))== NULL )
235239{
236240fprintf (stderr ,_ ("out of memory\n" ));
237241exit (1 );