diff options
author | Alvaro Herrera | 2024-09-25 14:42:02 +0000 |
---|---|---|
committer | Alvaro Herrera | 2024-09-25 14:42:02 +0000 |
commit | dce507356a4ab7d548dca9d7abf1800a0fc0a18e (patch) | |
tree | b4a093a413fde9f516efc457e05f09d9a8b15043 | |
parent | 1ab67c9dfaadda86059f405e5746efb6ddb9fe21 (diff) |
Turn 'if' condition around to avoid Svace complaint
The unwritten assumption of this code is that both events->head and
events->tail are NULL together (an empty list) or they aren't. So the
code was testing events->head for nullness and using that as a cue to
deference events->tail, which annoys the Svace static code analyzer.
We can silence it by testing events->tail member instead, and add an
assertion about events->head to ensure it's all consistent.
This code is very old and as far as we know, there's never been a bug
report related to this, so there's no need to backpatch.
This was found by the ALT Linux Team using Svace.
Author: Alexander Kuznetsov <[email protected]>
Discussion: https://postgr.es/m/[email protected]
-rw-r--r-- | src/backend/commands/trigger.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index 29d30bfb6f..3671e82535 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -4097,8 +4097,11 @@ afterTriggerAddEvent(AfterTriggerEventList *events, chunk->endptr = chunk->endfree = (char *) chunk + chunksize; Assert(chunk->endfree - chunk->freeptr >= needed); - if (events->head == NULL) + if (events->tail == NULL) + { + Assert(events->head == NULL); events->head = chunk; + } else events->tail->next = chunk; events->tail = chunk; |