mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-06 13:49:21 +02:00
Fix bogus casting in BlockIdGetBlockNumber().
This macro cast the result to BlockNumber after shifting, not before, which is the wrong thing. Per the C spec, the uint16 fields would promote to int not unsigned int, so that (for 32-bit int) the shift potentially shifts a nonzero bit into the sign position. I doubt there are any production systems where this would actually end with the wrong answer, but it is undefined behavior per the C spec, and clang's -fsanitize=undefined option reputedly warns about it on some platforms. (I can't reproduce that right now, but the code is undeniably wrong per spec.) It's easy to fix by casting to BlockNumber (uint32) in the proper places. It's been wrong for ages, so back-patch to all supported branches. Report and patch by Zhihong Yu (cosmetic tweaking by me) Discussion: https://postgr.es/m/CALNJ-vT9r0DSsAOw9OXVJFxLENoVS_68kJ5x0p44atoYH+H4dg@mail.gmail.com
This commit is contained in:
parent
f727b6ea8f
commit
4b0696b36e
@ -115,7 +115,7 @@ typedef BlockIdData *BlockId; /* block identifier */
|
|||||||
#define BlockIdGetBlockNumber(blockId) \
|
#define BlockIdGetBlockNumber(blockId) \
|
||||||
( \
|
( \
|
||||||
AssertMacro(BlockIdIsValid(blockId)), \
|
AssertMacro(BlockIdIsValid(blockId)), \
|
||||||
(BlockNumber) (((blockId)->bi_hi << 16) | ((uint16) (blockId)->bi_lo)) \
|
((((BlockNumber) (blockId)->bi_hi) << 16) | ((BlockNumber) (blockId)->bi_lo)) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#endif /* BLOCK_H */
|
#endif /* BLOCK_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user