aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-07-27 12:12:37 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2017-07-27 12:12:37 -0400
commit1e2f941db1671909ba3bde447c224bb64d1c002a (patch)
treee23f3206c913ca35d84b17955ee6f767c713136d /src
parentb884f629dcbac002a703ccaf0990d9467ae69a19 (diff)
downloadpostgresql-1e2f941db1671909ba3bde447c224bb64d1c002a.tar.gz
postgresql-1e2f941db1671909ba3bde447c224bb64d1c002a.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/describe.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 03ef1b070c1..4f4790cc5c4 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -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;
}