Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c6605c1

Browse files
committed
Don't test already-referenced pointer for nullness
Commit b8ba734 added in PQgetResult a derefence to a pointer returned by pqPrepareAsyncResult(), before some other code that was already testing that pointer for nullness. But since commit 618c167 (in Postgres 15), pqPrepareAsyncResult() doesn't ever return NULL (a statically-allocated result is returned if OOM). So in branches 15 and up, we can remove the redundant pointer check with no harm done. However, in branch 14, pqPrepareAsyncResult() can indeed return NULL if it runs out of memory. Fix things there by adding a null pointer check before dereferencing the pointer. This should hint Coverity that the preexisting check is not redundant but necessary. Backpatch to 14, like b8ba734. Per Coverity.
1 parent a37bb7c commit c6605c1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/interfaces/libpq/fe-exec.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,8 @@ pqSaveWriteError(PGconn *conn)
842842
* using whatever is in conn->errorMessage. In any case, clear the async
843843
* result storage, and update our notion of how much error text has been
844844
* returned to the application.
845+
*
846+
* Note that in no case (not even OOM) do we return NULL.
845847
*/
846848
PGresult *
847849
pqPrepareAsyncResult(PGconn *conn)
@@ -2138,7 +2140,7 @@ PQgetResult(PGconn *conn)
21382140
* (In other words: we don't return a NULL after a pipeline
21392141
* sync.)
21402142
*/
2141-
if (res && res->resultStatus == PGRES_PIPELINE_SYNC)
2143+
if (res->resultStatus == PGRES_PIPELINE_SYNC)
21422144
pqPipelineProcessQueue(conn);
21432145
}
21442146
else

0 commit comments

Comments
 (0)