mirror of
https://github.com/postgres/postgres.git
synced 2025-05-09 18:21:05 +03:00
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:
parent
b884f629dc
commit
1e2f941db1
@ -4113,7 +4113,7 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
|
|||||||
{
|
{
|
||||||
PQExpBufferData buf;
|
PQExpBufferData buf;
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
char title[1024];
|
PQExpBufferData title;
|
||||||
printQueryOpt myopt = pset.popt;
|
printQueryOpt myopt = pset.popt;
|
||||||
static const bool translate_columns[] = {true, false, false};
|
static const bool translate_columns[] = {true, false, false};
|
||||||
|
|
||||||
@ -4169,11 +4169,13 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
myopt.nullPrint = NULL;
|
myopt.nullPrint = NULL;
|
||||||
|
initPQExpBuffer(&title);
|
||||||
if (nspname)
|
if (nspname)
|
||||||
sprintf(title, _("Text search parser \"%s.%s\""), nspname, prsname);
|
printfPQExpBuffer(&title, _("Text search parser \"%s.%s\""),
|
||||||
|
nspname, prsname);
|
||||||
else
|
else
|
||||||
sprintf(title, _("Text search parser \"%s\""), prsname);
|
printfPQExpBuffer(&title, _("Text search parser \"%s\""), prsname);
|
||||||
myopt.title = title;
|
myopt.title = title.data;
|
||||||
myopt.footers = NULL;
|
myopt.footers = NULL;
|
||||||
myopt.topt.default_footer = false;
|
myopt.topt.default_footer = false;
|
||||||
myopt.translate_header = true;
|
myopt.translate_header = true;
|
||||||
@ -4202,10 +4204,11 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
|
|||||||
|
|
||||||
myopt.nullPrint = NULL;
|
myopt.nullPrint = NULL;
|
||||||
if (nspname)
|
if (nspname)
|
||||||
sprintf(title, _("Token types for parser \"%s.%s\""), nspname, prsname);
|
printfPQExpBuffer(&title, _("Token types for parser \"%s.%s\""),
|
||||||
|
nspname, prsname);
|
||||||
else
|
else
|
||||||
sprintf(title, _("Token types for parser \"%s\""), prsname);
|
printfPQExpBuffer(&title, _("Token types for parser \"%s\""), prsname);
|
||||||
myopt.title = title;
|
myopt.title = title.data;
|
||||||
myopt.footers = NULL;
|
myopt.footers = NULL;
|
||||||
myopt.topt.default_footer = true;
|
myopt.topt.default_footer = true;
|
||||||
myopt.translate_header = 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);
|
printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
|
||||||
|
|
||||||
|
termPQExpBuffer(&title);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -5004,7 +5008,7 @@ listOneExtensionContents(const char *extname, const char *oid)
|
|||||||
{
|
{
|
||||||
PQExpBufferData buf;
|
PQExpBufferData buf;
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
char title[1024];
|
PQExpBufferData title;
|
||||||
printQueryOpt myopt = pset.popt;
|
printQueryOpt myopt = pset.popt;
|
||||||
|
|
||||||
initPQExpBuffer(&buf);
|
initPQExpBuffer(&buf);
|
||||||
@ -5022,12 +5026,14 @@ listOneExtensionContents(const char *extname, const char *oid)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
myopt.nullPrint = NULL;
|
myopt.nullPrint = NULL;
|
||||||
snprintf(title, sizeof(title), _("Objects in extension \"%s\""), extname);
|
initPQExpBuffer(&title);
|
||||||
myopt.title = title;
|
printfPQExpBuffer(&title, _("Objects in extension \"%s\""), extname);
|
||||||
|
myopt.title = title.data;
|
||||||
myopt.translate_header = true;
|
myopt.translate_header = true;
|
||||||
|
|
||||||
printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
|
printQuery(res, &myopt, pset.queryFout, false, pset.logfile);
|
||||||
|
|
||||||
|
termPQExpBuffer(&title);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user