Skip to content

Commit 7b955c2

Browse files
committed
Fix bogus use of "long" in AllocSetCheck()
Because long is 32-bit on 64-bit Windows, it isn't a good datatype to store the difference between 2 pointers. The under-sized type could overflow and lead to scary warnings in MEMORY_CONTEXT_CHECKING builds, such as: WARNING: problem in alloc set ExecutorState: bad single-chunk %p in block %p However, the problem lies only in the code running the check, not from an actual memory accounting bug. Fix by using "Size" instead of "long". This means using an unsigned type rather than the previous signed type. If the block's freeptr was corrupted, we'd still catch that if the unsigned type wrapped. Unsigned allows us to avoid further needless complexities around comparing signed and unsigned types. Author: David Rowley <dgrowleyml@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Backpatch-through: 13 Discussion: https://postgr.es/m/CAApHDvo-RmiT4s33J=aC9C_-wPZjOXQ232V-EZFgKftSsNRi4w@mail.gmail.com
1 parent d916204 commit 7b955c2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/backend/utils/mmgr/aset.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,9 +1429,9 @@ AllocSetCheck(MemoryContext context)
14291429
prevblock = block, block = block->next)
14301430
{
14311431
char *bpoz = ((char *) block) + ALLOC_BLOCKHDRSZ;
1432-
long blk_used = block->freeptr - bpoz;
1433-
long blk_data = 0;
1434-
long nchunks = 0;
1432+
Size blk_used = block->freeptr - bpoz;
1433+
Size blk_data = 0;
1434+
Size nchunks = 0;
14351435

14361436
if (set->keeper == block)
14371437
total_allocated += block->endptr - ((char *) set);

0 commit comments

Comments
 (0)