mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
Must count '*' characters as potential arguments.
This commit is contained in:
parent
055467d504
commit
b79a718fac
@ -62,7 +62,7 @@
|
|||||||
* causing nasty effects.
|
* causing nasty effects.
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
|
||||||
/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.26 2005/03/20 13:54:53 momjian Exp $";*/
|
/*static char _id[] = "$PostgreSQL: pgsql/src/port/snprintf.c,v 1.27 2005/04/14 20:53:09 tgl Exp $";*/
|
||||||
|
|
||||||
static void dopr(char *buffer, const char *format, va_list args, char *end);
|
static void dopr(char *buffer, const char *format, va_list args, char *end);
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ dopr(char *buffer, const char *format, va_list args, char *end)
|
|||||||
int precision;
|
int precision;
|
||||||
int position;
|
int position;
|
||||||
char *output;
|
char *output;
|
||||||
int percents = 1;
|
int nargs = 1;
|
||||||
const char *p;
|
const char *p;
|
||||||
struct fmtpar
|
struct fmtpar
|
||||||
{
|
{
|
||||||
@ -220,18 +220,22 @@ dopr(char *buffer, const char *format, va_list args, char *end)
|
|||||||
int longlongflag;
|
int longlongflag;
|
||||||
} *fmtpar, **fmtparptr;
|
} *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++)
|
for (p = format; *p != '\0'; p++)
|
||||||
if (*p == '%') /* counts %% as two, so overcounts */
|
if (*p == '%' || *p == '*')
|
||||||
percents++;
|
nargs++;
|
||||||
|
|
||||||
/* Need to use malloc() because memory system might not be started yet. */
|
/* 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"));
|
fprintf(stderr, _("out of memory\n"));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if ((fmtparptr = malloc(sizeof(struct fmtpar *) * percents)) == NULL)
|
if ((fmtparptr = malloc(sizeof(struct fmtpar *) * nargs)) == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("out of memory\n"));
|
fprintf(stderr, _("out of memory\n"));
|
||||||
exit(1);
|
exit(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user