62
62
* causing nasty effects.
63
63
**************************************************************/
64
64
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 $";*/
66
66
67
67
static void dopr (char * buffer ,const char * format ,va_list args ,char * end );
68
68
@@ -194,7 +194,7 @@ dopr(char *buffer, const char *format, va_list args, char *end)
194
194
int precision ;
195
195
int position ;
196
196
char * output ;
197
- int percents = 1 ;
197
+ int nargs = 1 ;
198
198
const char * p ;
199
199
struct fmtpar
200
200
{
@@ -220,18 +220,22 @@ dopr(char *buffer, const char *format, va_list args, char *end)
220
220
int longlongflag ;
221
221
}* fmtpar ,* * fmtparptr ;
222
222
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
+ */
224
228
for (p = format ;* p != '\0' ;p ++ )
225
- if (* p == '%' ) /* counts %% as two, so overcounts */
226
- percents ++ ;
229
+ if (* p == '%' || * p == '*' )
230
+ nargs ++ ;
227
231
228
232
/* 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 )
230
234
{
231
235
fprintf (stderr ,_ ("out of memory\n" ));
232
236
exit (1 );
233
237
}
234
- if ((fmtparptr = malloc (sizeof (struct fmtpar * )* percents ))== NULL )
238
+ if ((fmtparptr = malloc (sizeof (struct fmtpar * )* nargs ))== NULL )
235
239
{
236
240
fprintf (stderr ,_ ("out of memory\n" ));
237
241
exit (1 );