Don't test already-referenced pointer for nullness
authorAlvaro Herrera <[email protected]>
Tue, 16 Jan 2024 11:27:52 +0000 (12:27 +0100)
committerAlvaro Herrera <[email protected]>
Tue, 16 Jan 2024 11:27:52 +0000 (12:27 +0100)
commit7a7c8c98a610418ed0118e22a1793bf27e55783a
tree1bbbd6457697052a0577bd1c4223af1ce7a70afb
parentc7edaeec50546e10b15e27de94fdea1252cbe76b
Don't test already-referenced pointer for nullness

Commit b8ba7344e9eb 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
618c16707a6d (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 b8ba7344e9eb.

Per Coverity.
src/interfaces/libpq/fe-exec.c