Skip to content

Commit 43211c2

Browse files
committed
initdb: Use varargs macro for PG_CMD_PRINTF
I left PG_CMD_PUTS around even though it could be handled by PG_CMD_PRINTF since PG_CMD_PUTS is sometimes called with non-literal arguments, and so that would create a potential problem if such a string contained percent signs. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
1 parent e94cd0a commit 43211c2

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

src/bin/initdb/initdb.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -307,21 +307,9 @@ do { \
307307
output_failed = true, output_errno = errno; \
308308
} while (0)
309309

310-
#define PG_CMD_PRINTF1(fmt, arg1) \
310+
#define PG_CMD_PRINTF(fmt, ...) \
311311
do { \
312-
if (fprintf(cmdfd, fmt, arg1) < 0 || fflush(cmdfd) < 0) \
313-
output_failed = true, output_errno = errno; \
314-
} while (0)
315-
316-
#define PG_CMD_PRINTF2(fmt, arg1, arg2) \
317-
do { \
318-
if (fprintf(cmdfd, fmt, arg1, arg2) < 0 || fflush(cmdfd) < 0) \
319-
output_failed = true, output_errno = errno; \
320-
} while (0)
321-
322-
#define PG_CMD_PRINTF3(fmt, arg1, arg2, arg3) \
323-
do { \
324-
if (fprintf(cmdfd, fmt, arg1, arg2, arg3) < 0 || fflush(cmdfd) < 0) \
312+
if (fprintf(cmdfd, fmt, __VA_ARGS__) < 0 || fflush(cmdfd) < 0) \
325313
output_failed = true, output_errno = errno; \
326314
} while (0)
327315

@@ -1490,7 +1478,7 @@ setup_auth(FILE *cmdfd)
14901478
PG_CMD_PUTS(*line);
14911479

14921480
if (superuser_password)
1493-
PG_CMD_PRINTF2("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n",
1481+
PG_CMD_PRINTF("ALTER USER \"%s\" WITH PASSWORD E'%s';\n\n",
14941482
username, escape_quotes(superuser_password));
14951483
}
14961484

@@ -1684,7 +1672,7 @@ setup_description(FILE *cmdfd)
16841672
" objsubid int4, "
16851673
" description text);\n\n");
16861674

1687-
PG_CMD_PRINTF1("COPY tmp_pg_description FROM E'%s';\n\n",
1675+
PG_CMD_PRINTF("COPY tmp_pg_description FROM E'%s';\n\n",
16881676
escape_quotes(desc_file));
16891677

16901678
PG_CMD_PUTS("INSERT INTO pg_description "
@@ -1697,7 +1685,7 @@ setup_description(FILE *cmdfd)
16971685
" classname name, "
16981686
" description text);\n\n");
16991687

1700-
PG_CMD_PRINTF1("COPY tmp_pg_shdescription FROM E'%s';\n\n",
1688+
PG_CMD_PRINTF("COPY tmp_pg_shdescription FROM E'%s';\n\n",
17011689
escape_quotes(shdesc_file));
17021690

17031691
PG_CMD_PUTS("INSERT INTO pg_shdescription "
@@ -1738,7 +1726,7 @@ setup_collation(FILE *cmdfd)
17381726
* in pg_collation.h. But add it before reading system collations, so
17391727
* that it wins if libc defines a locale named ucs_basic.
17401728
*/
1741-
PG_CMD_PRINTF3("INSERT INTO pg_collation (oid, collname, collnamespace, collowner, collprovider, collisdeterministic, collencoding, collcollate, collctype)"
1729+
PG_CMD_PRINTF("INSERT INTO pg_collation (oid, collname, collnamespace, collowner, collprovider, collisdeterministic, collencoding, collcollate, collctype)"
17421730
"VALUES (pg_nextoid('pg_catalog.pg_collation', 'oid', 'pg_catalog.pg_collation_oid_index'), 'ucs_basic', 'pg_catalog'::regnamespace, %u, '%c', true, %d, 'C', 'C');\n\n",
17431731
BOOTSTRAP_SUPERUSERID, COLLPROVIDER_LIBC, PG_UTF8);
17441732

@@ -1982,12 +1970,12 @@ setup_schema(FILE *cmdfd)
19821970

19831971
free(lines);
19841972

1985-
PG_CMD_PRINTF1("UPDATE information_schema.sql_implementation_info "
1973+
PG_CMD_PRINTF("UPDATE information_schema.sql_implementation_info "
19861974
" SET character_value = '%s' "
19871975
" WHERE implementation_info_name = 'DBMS VERSION';\n\n",
19881976
infoversion);
19891977

1990-
PG_CMD_PRINTF1("COPY information_schema.sql_features "
1978+
PG_CMD_PRINTF("COPY information_schema.sql_features "
19911979
" (feature_id, feature_name, sub_feature_id, "
19921980
" sub_feature_name, is_supported, comments) "
19931981
" FROM E'%s';\n\n",

0 commit comments

Comments
 (0)