Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1e2f941

Browse files
committed
Avoid use of sprintf/snprintf in describe.c.
Most places were already using the PQExpBuffer library for constructingvariable-length strings; bring the two stragglers into line.describeOneTSParser was living particularly dangerously since it wasn'teven using snprintf().Daniel GustafssonDiscussion:https://postgr.es/m/3641F19B-336A-431A-86CE-A80562505C5E@yesql.se
1 parentb884f62 commit1e2f941

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

‎src/bin/psql/describe.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,7 +4113,7 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
41134113
{
41144114
PQExpBufferDatabuf;
41154115
PGresult*res;
4116-
chartitle[1024];
4116+
PQExpBufferDatatitle;
41174117
printQueryOptmyopt=pset.popt;
41184118
staticconstbooltranslate_columns[]= {true, false, false};
41194119

@@ -4169,11 +4169,13 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
41694169
return false;
41704170

41714171
myopt.nullPrint=NULL;
4172+
initPQExpBuffer(&title);
41724173
if (nspname)
4173-
sprintf(title,_("Text search parser \"%s.%s\""),nspname,prsname);
4174+
printfPQExpBuffer(&title,_("Text search parser \"%s.%s\""),
4175+
nspname,prsname);
41744176
else
4175-
sprintf(title,_("Text search parser \"%s\""),prsname);
4176-
myopt.title=title;
4177+
printfPQExpBuffer(&title,_("Text search parser \"%s\""),prsname);
4178+
myopt.title=title.data;
41774179
myopt.footers=NULL;
41784180
myopt.topt.default_footer= false;
41794181
myopt.translate_header= true;
@@ -4202,10 +4204,11 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
42024204

42034205
myopt.nullPrint=NULL;
42044206
if (nspname)
4205-
sprintf(title,_("Token types for parser \"%s.%s\""),nspname,prsname);
4207+
printfPQExpBuffer(&title,_("Token types for parser \"%s.%s\""),
4208+
nspname,prsname);
42064209
else
4207-
sprintf(title,_("Token types for parser \"%s\""),prsname);
4208-
myopt.title=title;
4210+
printfPQExpBuffer(&title,_("Token types for parser \"%s\""),prsname);
4211+
myopt.title=title.data;
42094212
myopt.footers=NULL;
42104213
myopt.topt.default_footer= true;
42114214
myopt.translate_header= true;
@@ -4214,6 +4217,7 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
42144217

42154218
printQuery(res,&myopt,pset.queryFout, false,pset.logfile);
42164219

4220+
termPQExpBuffer(&title);
42174221
PQclear(res);
42184222
return true;
42194223
}
@@ -5004,7 +5008,7 @@ listOneExtensionContents(const char *extname, const char *oid)
50045008
{
50055009
PQExpBufferDatabuf;
50065010
PGresult*res;
5007-
chartitle[1024];
5011+
PQExpBufferDatatitle;
50085012
printQueryOptmyopt=pset.popt;
50095013

50105014
initPQExpBuffer(&buf);
@@ -5022,12 +5026,14 @@ listOneExtensionContents(const char *extname, const char *oid)
50225026
return false;
50235027

50245028
myopt.nullPrint=NULL;
5025-
snprintf(title,sizeof(title),_("Objects in extension \"%s\""),extname);
5026-
myopt.title=title;
5029+
initPQExpBuffer(&title);
5030+
printfPQExpBuffer(&title,_("Objects in extension \"%s\""),extname);
5031+
myopt.title=title.data;
50275032
myopt.translate_header= true;
50285033

50295034
printQuery(res,&myopt,pset.queryFout, false,pset.logfile);
50305035

5036+
termPQExpBuffer(&title);
50315037
PQclear(res);
50325038
return true;
50335039
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp