Skip to content

Commit 390edee

Browse files
committed
psql: Fix some scan-build warnings
A repeated complaint was that scan-build thought that if the \timing setting changes during processing of a query, the post-processing might read garbage time values. This is probably not possible right now, but it's not entirely inconceivable given the code structure. So silence this warning with small restructuring that makes this more robust. The other warnings were a few dead stores that are easy to remove. Discussion: https://www.postgresql.org/message-id/2570e2ae-fa0f-aac9-f72f-bb59a9983a20@enterprisedb.com
1 parent 00c61a7 commit 390edee

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

src/bin/psql/common.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ PSQLexec(const char *query)
594594
int
595595
PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE *printQueryFout)
596596
{
597+
bool timing = pset.timing;
597598
PGresult *res;
598599
double elapsed_msec = 0;
599600
instr_time before;
@@ -608,7 +609,7 @@ PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE *printQueryFout)
608609

609610
SetCancelConn(pset.db);
610611

611-
if (pset.timing)
612+
if (timing)
612613
INSTR_TIME_SET_CURRENT(before);
613614

614615
res = PQexec(pset.db, query);
@@ -621,7 +622,7 @@ PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE *printQueryFout)
621622
return 0;
622623
}
623624

624-
if (pset.timing)
625+
if (timing)
625626
{
626627
INSTR_TIME_SET_CURRENT(after);
627628
INSTR_TIME_SUBTRACT(after, before);
@@ -674,7 +675,7 @@ PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE *printQueryFout)
674675
fflush(fout);
675676

676677
/* Possible microtiming output */
677-
if (pset.timing)
678+
if (timing)
678679
PrintTiming(elapsed_msec);
679680

680681
return 1;
@@ -1192,6 +1193,7 @@ PrintQueryResults(PGresult *results)
11921193
bool
11931194
SendQuery(const char *query)
11941195
{
1196+
bool timing = pset.timing;
11951197
PGresult *results;
11961198
PGTransactionStatusType transaction_status;
11971199
double elapsed_msec = 0;
@@ -1300,7 +1302,7 @@ SendQuery(const char *query)
13001302
instr_time before,
13011303
after;
13021304

1303-
if (pset.timing)
1305+
if (timing)
13041306
INSTR_TIME_SET_CURRENT(before);
13051307

13061308
results = PQexec(pset.db, query);
@@ -1309,7 +1311,7 @@ SendQuery(const char *query)
13091311
ResetCancelConn();
13101312
OK = ProcessResult(&results);
13111313

1312-
if (pset.timing)
1314+
if (timing)
13131315
{
13141316
INSTR_TIME_SET_CURRENT(after);
13151317
INSTR_TIME_SUBTRACT(after, before);
@@ -1400,7 +1402,7 @@ SendQuery(const char *query)
14001402
ClearOrSaveResult(results);
14011403

14021404
/* Possible microtiming output */
1403-
if (pset.timing)
1405+
if (timing)
14041406
PrintTiming(elapsed_msec);
14051407

14061408
/* check for events that may occur during query execution */
@@ -1471,14 +1473,15 @@ SendQuery(const char *query)
14711473
static bool
14721474
DescribeQuery(const char *query, double *elapsed_msec)
14731475
{
1476+
bool timing = pset.timing;
14741477
PGresult *results;
14751478
bool OK;
14761479
instr_time before,
14771480
after;
14781481

14791482
*elapsed_msec = 0;
14801483

1481-
if (pset.timing)
1484+
if (timing)
14821485
INSTR_TIME_SET_CURRENT(before);
14831486

14841487
/*
@@ -1550,7 +1553,7 @@ DescribeQuery(const char *query, double *elapsed_msec)
15501553
results = PQexec(pset.db, buf.data);
15511554
OK = AcceptResult(results);
15521555

1553-
if (pset.timing)
1556+
if (timing)
15541557
{
15551558
INSTR_TIME_SET_CURRENT(after);
15561559
INSTR_TIME_SUBTRACT(after, before);
@@ -1591,6 +1594,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
15911594
PGresult *results;
15921595
PQExpBufferData buf;
15931596
printQueryOpt my_popt = pset.popt;
1597+
bool timing = pset.timing;
15941598
FILE *fout;
15951599
bool is_pipe;
15961600
bool is_pager = false;
@@ -1610,7 +1614,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
16101614
my_popt.topt.stop_table = false;
16111615
my_popt.topt.prior_records = 0;
16121616

1613-
if (pset.timing)
1617+
if (timing)
16141618
INSTR_TIME_SET_CURRENT(before);
16151619

16161620
/* if we're not in a transaction, start one */
@@ -1640,7 +1644,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
16401644
if (!OK)
16411645
goto cleanup;
16421646

1643-
if (pset.timing)
1647+
if (timing)
16441648
{
16451649
INSTR_TIME_SET_CURRENT(after);
16461650
INSTR_TIME_SUBTRACT(after, before);
@@ -1682,13 +1686,13 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
16821686

16831687
for (;;)
16841688
{
1685-
if (pset.timing)
1689+
if (timing)
16861690
INSTR_TIME_SET_CURRENT(before);
16871691

16881692
/* get fetch_count tuples at a time */
16891693
results = PQexec(pset.db, fetch_cmd);
16901694

1691-
if (pset.timing)
1695+
if (timing)
16921696
{
16931697
INSTR_TIME_SET_CURRENT(after);
16941698
INSTR_TIME_SUBTRACT(after, before);
@@ -1802,7 +1806,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
18021806
}
18031807

18041808
cleanup:
1805-
if (pset.timing)
1809+
if (timing)
18061810
INSTR_TIME_SET_CURRENT(before);
18071811

18081812
/*
@@ -1828,7 +1832,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
18281832
ClearOrSaveResult(results);
18291833
}
18301834

1831-
if (pset.timing)
1835+
if (timing)
18321836
{
18331837
INSTR_TIME_SET_CURRENT(after);
18341838
INSTR_TIME_SUBTRACT(after, before);

src/bin/psql/copy.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
660660
if (PQputCopyData(conn, buf, buflen) <= 0)
661661
{
662662
OK = false;
663-
copydone = true;
664663
break;
665664
}
666665

src/bin/psql/describe.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,6 @@ describeFunctions(const char *functypes, const char *func_pattern,
635635
appendPQExpBufferStr(&buf, "p.prokind = 'w'\n");
636636
else
637637
appendPQExpBufferStr(&buf, "p.proiswindow\n");
638-
needs_or = true;
639638
}
640639
appendPQExpBufferStr(&buf, " )\n");
641640
}

0 commit comments

Comments
 (0)