bufmgr: Fix signedness of mask variable in BufferSync()
authorAndres Freund <[email protected]>
Wed, 8 Oct 2025 18:34:30 +0000 (14:34 -0400)
committerAndres Freund <[email protected]>
Wed, 8 Oct 2025 18:34:30 +0000 (14:34 -0400)
BM_PERMANENT is defined as 1U<<31, which is a negative number when interpreted
as a signed integer. Unfortunately the mask variable in BufferSync() was
signed. This has been wrong for a long time, but failed to fail, due to
integer conversion rules.

However, in an upcoming patch the width of the state variable will be
increased, with the wrong signedness leading to never flushing permanent
buffers - luckily caught in a test.

It seems better to fix this separately, instead of doing so as part of a
large, otherwise mechanical, patch.

Reviewed-by: Matthias van de Meent <[email protected]>
Discussion: https://postgr.es/m/fvfmkr5kk4nyex56ejgxj3uzi63isfxovp2biecb4bspbjrze7@az2pljabhnff

src/backend/storage/buffer/bufmgr.c

index fd462a25beb820c426c2f989b5539bf1d4eb1330..8ee7d3b441b07f5b82806447d378a8fd6df7d1e0 100644 (file)
@@ -3321,7 +3321,7 @@ BufferSync(int flags)
    Oid         last_tsid;
    binaryheap *ts_heap;
    int         i;
-   int         mask = BM_DIRTY;
+   uint32      mask = BM_DIRTY;
    WritebackContext wb_context;
 
    /*