Skip to content

Commit b79a718

Browse files
committed
Must count '*' characters as potential arguments.
1 parent 055467d commit b79a718

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/port/snprintf.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
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

6767
static 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)
194194
int precision;
195195
int position;
196196
char *output;
197-
int percents = 1;
197+
int nargs = 1;
198198
const char *p;
199199
struct fmtpar
200200
{
@@ -220,18 +220,22 @@ dopr(char *buffer, const char *format, va_list args, char *end)
220220
int 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+
*/
224228
for (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
{
231235
fprintf(stderr, _("out of memory\n"));
232236
exit(1);
233237
}
234-
if ((fmtparptr = malloc(sizeof(struct fmtpar *) * percents)) == NULL)
238+
if ((fmtparptr = malloc(sizeof(struct fmtpar *) * nargs)) == NULL)
235239
{
236240
fprintf(stderr, _("out of memory\n"));
237241
exit(1);

0 commit comments

Comments
 (0)