Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit97031f4

Browse files
committed
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 wouldpromote to int not unsigned int, so that (for 32-bit int) the shiftpotentially shifts a nonzero bit into the sign position. I doubtthere are any production systems where this would actually end withthe wrong answer, but it is undefined behavior per the C spec, andclang's -fsanitize=undefined option reputedly warns about it on someplatforms. (I can't reproduce that right now, but the code isundeniably wrong per spec.) It's easy to fix by casting toBlockNumber (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
1 parent1a027e6 commit97031f4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎src/include/storage/block.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ typedef BlockIdData *BlockId;/* block identifier */
115115
#defineBlockIdGetBlockNumber(blockId) \
116116
( \
117117
AssertMacro(BlockIdIsValid(blockId)), \
118-
(BlockNumber) (((blockId)->bi_hi << 16) | ((uint16) (blockId)->bi_lo)) \
118+
((((BlockNumber) (blockId)->bi_hi) << 16) | ((BlockNumber) (blockId)->bi_lo)) \
119119
)
120120

121121
#endif/* BLOCK_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp