Avoid use of sprintf/snprintf in describe.c.

Most places were already using the PQExpBuffer library for constructing
variable-length strings; bring the two stragglers into line.
describeOneTSParser was living particularly dangerously since it wasn't
even using snprintf().

Daniel Gustafsson

Discussion: https://postgr.es/m/3641F19B-336A-431A-86CE-A80562505C5E@yesql.se
This commit is contained in:
Tom Lane 2017-07-27 12:12:37 -04:00
parent b884f629dc
commit 1e2f941db1
1 changed files with 16 additions and 10 deletions

View File

@ -4113,7 +4113,7 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
{
PQExpBufferData buf;
PGresult *res;
char title[1024];
PQExpBufferData title;
printQueryOpt myopt = pset.popt;
static const bool translate_columns[] = {true, false, false};
@ -4169,11 +4169,13 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
return false;
myopt.nullPrint = NULL;
initPQExpBuffer(&title);
if (nspname)
sprintf(title, _("Text search parser \"%s.%s\""), nspname, prsname);
printfPQExpBuffer(&title, _("Text search parser \"%s.%s\""),
nspname, prsname);
else
sprintf(title, _("Text search parser \"%s\""), prsname);
myopt.title = title;
printfPQExpBuffer(&title, _("Text search parser \"%s\""), prsname);
myopt.title = title.data;
myopt.footers = NULL;
myopt.topt.default_footer = false;
myopt.translate_header = true;
@ -4202,10 +4204,11 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
myopt.nullPrint = NULL;
if (nspname)
sprintf(title, _("Token types for parser \"%s.%s\""), nspname, prsname);
printfPQExpBuffer(&title, _("Token types for parser \"%s.%s\""),
nspname, prsname);
else
sprintf(title, _("Token types for parser \"%s\""), prsname);
myopt.title = title;
printfPQExpBuffer(&title, _("Token types for parser \"%s\""), prsname);
myopt.title = title.data;
myopt.footers = NULL;
myopt.topt.default_footer = true;
myopt.translate_header = true;
@ -4214,6 +4217,7 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
termPQExpBuffer(&title);
PQclear(res);
return true;
}
@ -5004,7 +5008,7 @@ listOneExtensionContents(const char *extname, const char *oid)
{
PQExpBufferData buf;
PGresult *res;
char title[1024];
PQExpBufferData title;
printQueryOpt myopt = pset.popt;
initPQExpBuffer(&buf);
@ -5022,12 +5026,14 @@ listOneExtensionContents(const char *extname, const char *oid)
return false;
myopt.nullPrint = NULL;
snprintf(title, sizeof(title), _("Objects in extension \"%s\""), extname);
myopt.title = title;
initPQExpBuffer(&title);
printfPQExpBuffer(&title, _("Objects in extension \"%s\""), extname);
myopt.title = title.data;
myopt.translate_header = true;
printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
termPQExpBuffer(&title);
PQclear(res);
return true;
}