From: David Rowley Date: Fri, 16 Aug 2024 22:36:23 +0000 (+1200) Subject: Relocate a badly placed Assert in COPY FROM code X-Git-Tag: REL_18_BETA1~2106 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=bd8fe12ef3f727ed3658daf9b26beaf2b891e9bc;p=postgresql.git Relocate a badly placed Assert in COPY FROM code There's not much point in asserting a pointer isn't NULL after some code has already dereferenced that pointer. Adjust the code so that the Assert occurs before the pointer dereference. The Assert probably has questionable value in the first place, but it seems worth keeping around to document the contract between CopyMultiInsertInfoNextFreeSlot() and its callers. Author: Amul Sul Discussion: https://postgr.es/m/CAAJ_b94hXQzXaJxTLShkxQUgezf_SUxhzX9TH2f-g6gP7bne7g@mail.gmail.com --- diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c index ca85270be6d..2d3462913e1 100644 --- a/src/backend/commands/copyfrom.c +++ b/src/backend/commands/copyfrom.c @@ -597,10 +597,12 @@ CopyMultiInsertInfoNextFreeSlot(CopyMultiInsertInfo *miinfo, ResultRelInfo *rri) { CopyMultiInsertBuffer *buffer = rri->ri_CopyMultiInsertBuffer; - int nused = buffer->nused; + int nused; Assert(buffer != NULL); - Assert(nused < MAX_BUFFERED_TUPLES); + Assert(buffer->nused < MAX_BUFFERED_TUPLES); + + nused = buffer->nused; if (buffer->slots[nused] == NULL) buffer->slots[nused] = table_slot_create(rri->ri_RelationDesc, NULL);