summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2005-04-14 20:53:09 +0000
committerTom Lane2005-04-14 20:53:09 +0000
commit97a2a82d5709756da424eb97561fada6684b2a78 (patch)
tree271cca7434e48e03aac558822ece1fcc0bfcc934
parent0661acaa4ec1a9524672c09138179c82af91d5bc (diff)
Must count '*' characters as potential arguments.
-rw-r--r--src/port/snprintf.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/port/snprintf.c b/src/port/snprintf.c
index c48f7336dd..18f6afab59 100644
--- a/src/port/snprintf.c
+++ b/src/port/snprintf.c
@@ -194,7 +194,7 @@ dopr(char *buffer, const char *format, va_list args, char *end)
int precision;
int position;
char *output;
- int percents = 1;
+ int nargs = 1;
const char *p;
struct fmtpar
{
@@ -220,18 +220,22 @@ dopr(char *buffer, const char *format, va_list args, char *end)
int longlongflag;
} *fmtpar, **fmtparptr;
- /* Create enough structures to hold all arguments */
+ /*
+ * Create enough structures to hold all arguments. This overcounts,
+ * eg not all '*' characters are necessarily arguments, but it's not
+ * worth being exact.
+ */
for (p = format; *p != '\0'; p++)
- if (*p == '%') /* counts %% as two, so overcounts */
- percents++;
+ if (*p == '%' || *p == '*')
+ nargs++;
/* Need to use malloc() because memory system might not be started yet. */
- if ((fmtpar = malloc(sizeof(struct fmtpar) * percents)) == NULL)
+ if ((fmtpar = malloc(sizeof(struct fmtpar) * nargs)) == NULL)
{
fprintf(stderr, _("out of memory\n"));
exit(1);
}
- if ((fmtparptr = malloc(sizeof(struct fmtpar *) * percents)) == NULL)
+ if ((fmtparptr = malloc(sizeof(struct fmtpar *) * nargs)) == NULL)
{
fprintf(stderr, _("out of memory\n"));
exit(1);