From a22503f8c95655d4ce0917bfcc61d5d43deef325 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 26 Nov 2026 11:44:54 +0100 Subject: [PATCH] Fix clang bounds sanitizer failure with parallelCurrentXids Commit 7a04cac0c3b annotated SerializedTransactionState.parallelCurrentXids with the counted_by attribute. Code that takes the address of the array as ¶llelCurrentXids[0] is then treated by clang's -fsanitize=bounds as an access at index 0, which fails when nParallelCurrentXids is 0, for example when a parallel query is run in a transaction without an assigned XID. (The first change in this patch cannot fail because it is guarded by a positive count, but it is changed for consistency.) GCC allows this, and it's unclear whether this error by Clang is intended or correct. See for a Clang bug report. To fix, use plain array-to-pointer decay instead. This is simpler and more standard style anyway. Discussion: https://www.postgresql.org/message-id/flat/DKBEBF32QLUA.3L2DJRPUYNKHZ%40partin.io --- src/backend/access/transam/xact.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index d8d91bed427..623e8e3307c 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -5666,7 +5666,7 @@ SerializeTransactionState(Size maxsize, char *start_address) if (nParallelCurrentXids > 0) { result->nParallelCurrentXids = nParallelCurrentXids; - memcpy(&result->parallelCurrentXids[0], ParallelCurrentXids, + memcpy(result->parallelCurrentXids, ParallelCurrentXids, nParallelCurrentXids * sizeof(TransactionId)); return; } @@ -5702,7 +5702,7 @@ SerializeTransactionState(Size maxsize, char *start_address) /* Copy data into output area. */ result->nParallelCurrentXids = nxids; - memcpy(&result->parallelCurrentXids[0], workspace, + memcpy(result->parallelCurrentXids, workspace, nxids * sizeof(TransactionId)); } @@ -5727,7 +5727,7 @@ StartParallelWorkerTransaction(char *tstatespace) tstate->currentFullTransactionId; currentCommandId = tstate->currentCommandId; nParallelCurrentXids = tstate->nParallelCurrentXids; - ParallelCurrentXids = &tstate->parallelCurrentXids[0]; + ParallelCurrentXids = tstate->parallelCurrentXids; CurrentTransactionState->blockState = TBLOCK_PARALLEL_INPROGRESS; } -- 2.56.0