mirror of
https://github.com/postgres/postgres.git
synced 2025-05-28 00:03:23 -04:00
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
This commit is contained in:
parent
00c61a74bc
commit
390edeeb57
@ -594,6 +594,7 @@ PSQLexec(const char *query)
|
||||
int
|
||||
PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE *printQueryFout)
|
||||
{
|
||||
bool timing = pset.timing;
|
||||
PGresult *res;
|
||||
double elapsed_msec = 0;
|
||||
instr_time before;
|
||||
@ -608,7 +609,7 @@ PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE *printQueryFout)
|
||||
|
||||
SetCancelConn(pset.db);
|
||||
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
INSTR_TIME_SET_CURRENT(before);
|
||||
|
||||
res = PQexec(pset.db, query);
|
||||
@ -621,7 +622,7 @@ PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE *printQueryFout)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
{
|
||||
INSTR_TIME_SET_CURRENT(after);
|
||||
INSTR_TIME_SUBTRACT(after, before);
|
||||
@ -674,7 +675,7 @@ PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE *printQueryFout)
|
||||
fflush(fout);
|
||||
|
||||
/* Possible microtiming output */
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
PrintTiming(elapsed_msec);
|
||||
|
||||
return 1;
|
||||
@ -1192,6 +1193,7 @@ PrintQueryResults(PGresult *results)
|
||||
bool
|
||||
SendQuery(const char *query)
|
||||
{
|
||||
bool timing = pset.timing;
|
||||
PGresult *results;
|
||||
PGTransactionStatusType transaction_status;
|
||||
double elapsed_msec = 0;
|
||||
@ -1300,7 +1302,7 @@ SendQuery(const char *query)
|
||||
instr_time before,
|
||||
after;
|
||||
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
INSTR_TIME_SET_CURRENT(before);
|
||||
|
||||
results = PQexec(pset.db, query);
|
||||
@ -1309,7 +1311,7 @@ SendQuery(const char *query)
|
||||
ResetCancelConn();
|
||||
OK = ProcessResult(&results);
|
||||
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
{
|
||||
INSTR_TIME_SET_CURRENT(after);
|
||||
INSTR_TIME_SUBTRACT(after, before);
|
||||
@ -1400,7 +1402,7 @@ SendQuery(const char *query)
|
||||
ClearOrSaveResult(results);
|
||||
|
||||
/* Possible microtiming output */
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
PrintTiming(elapsed_msec);
|
||||
|
||||
/* check for events that may occur during query execution */
|
||||
@ -1471,6 +1473,7 @@ sendquery_cleanup:
|
||||
static bool
|
||||
DescribeQuery(const char *query, double *elapsed_msec)
|
||||
{
|
||||
bool timing = pset.timing;
|
||||
PGresult *results;
|
||||
bool OK;
|
||||
instr_time before,
|
||||
@ -1478,7 +1481,7 @@ DescribeQuery(const char *query, double *elapsed_msec)
|
||||
|
||||
*elapsed_msec = 0;
|
||||
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
INSTR_TIME_SET_CURRENT(before);
|
||||
|
||||
/*
|
||||
@ -1550,7 +1553,7 @@ DescribeQuery(const char *query, double *elapsed_msec)
|
||||
results = PQexec(pset.db, buf.data);
|
||||
OK = AcceptResult(results);
|
||||
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
{
|
||||
INSTR_TIME_SET_CURRENT(after);
|
||||
INSTR_TIME_SUBTRACT(after, before);
|
||||
@ -1591,6 +1594,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
|
||||
PGresult *results;
|
||||
PQExpBufferData buf;
|
||||
printQueryOpt my_popt = pset.popt;
|
||||
bool timing = pset.timing;
|
||||
FILE *fout;
|
||||
bool is_pipe;
|
||||
bool is_pager = false;
|
||||
@ -1610,7 +1614,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
|
||||
my_popt.topt.stop_table = false;
|
||||
my_popt.topt.prior_records = 0;
|
||||
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
INSTR_TIME_SET_CURRENT(before);
|
||||
|
||||
/* if we're not in a transaction, start one */
|
||||
@ -1640,7 +1644,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
|
||||
if (!OK)
|
||||
goto cleanup;
|
||||
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
{
|
||||
INSTR_TIME_SET_CURRENT(after);
|
||||
INSTR_TIME_SUBTRACT(after, before);
|
||||
@ -1682,13 +1686,13 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
INSTR_TIME_SET_CURRENT(before);
|
||||
|
||||
/* get fetch_count tuples at a time */
|
||||
results = PQexec(pset.db, fetch_cmd);
|
||||
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
{
|
||||
INSTR_TIME_SET_CURRENT(after);
|
||||
INSTR_TIME_SUBTRACT(after, before);
|
||||
@ -1802,7 +1806,7 @@ ExecQueryUsingCursor(const char *query, double *elapsed_msec)
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
INSTR_TIME_SET_CURRENT(before);
|
||||
|
||||
/*
|
||||
@ -1828,7 +1832,7 @@ cleanup:
|
||||
ClearOrSaveResult(results);
|
||||
}
|
||||
|
||||
if (pset.timing)
|
||||
if (timing)
|
||||
{
|
||||
INSTR_TIME_SET_CURRENT(after);
|
||||
INSTR_TIME_SUBTRACT(after, before);
|
||||
|
@ -660,7 +660,6 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
|
||||
if (PQputCopyData(conn, buf, buflen) <= 0)
|
||||
{
|
||||
OK = false;
|
||||
copydone = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -635,7 +635,6 @@ describeFunctions(const char *functypes, const char *func_pattern,
|
||||
appendPQExpBufferStr(&buf, "p.prokind = 'w'\n");
|
||||
else
|
||||
appendPQExpBufferStr(&buf, "p.proiswindow\n");
|
||||
needs_or = true;
|
||||
}
|
||||
appendPQExpBufferStr(&buf, " )\n");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user