]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Switch Get[Local]BufferDescriptor() to use a signed value in input
authorMichael Paquier <michael@paquier.xyz>
Fri, 3 Jul 2026 03:07:30 +0000 (12:07 +0900)
committerMichael Paquier <michael@paquier.xyz>
Fri, 3 Jul 2026 03:07:30 +0000 (12:07 +0900)
GetBufferDescriptor() and GetLocalBufferDescriptor() took a uint32
buffer index, but every real caller derives the index from a Buffer:
- Unsigned value for shared buffers.
- Signed value for local buffers.

Both routines now take in input a signed number, GetBufferDescriptor()
gaining an assertion checking that the input value is in the range
allowed by the GUC shared_buffers.  This work is a follow-up of
e18b0cb7344c, where we found that passing down a value for a local
buffer was undetected and finished outside the range of NBuffers.

While monitoring all the existing callers of *BufferDescriptor(), the
only consumer that passes does an unsigned value is ClockSweepTick(),
whose result is always a module of NBuffers.

Suggested-by: Andres Freund <andres@anarazel.de>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAExHW5uzRMYVZsXXS3HXXT0fG_sNrpUhUqwP4NorhaCqH9JDhA@mail.gmail.com

src/include/storage/buf_internals.h

index 89615a254a3edc94164f888a41e082da9c4ff712..2a1ffcc6c5c390cd11b0507f401c9316fc15c26e 100644 (file)
@@ -419,13 +419,15 @@ extern PGDLLIMPORT BufferDesc *LocalBufferDescriptors;
 
 
 static inline BufferDesc *
-GetBufferDescriptor(uint32 id)
+GetBufferDescriptor(int id)
 {
+       Assert(id >= 0 && id < NBuffers);
+
        return &(BufferDescriptors[id]).bufferdesc;
 }
 
 static inline BufferDesc *
-GetLocalBufferDescriptor(uint32 id)
+GetLocalBufferDescriptor(int id)
 {
        return &LocalBufferDescriptors[id];
 }