pgsql: Fix bogus casting in BlockIdGetBlockNumber().

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix bogus casting in BlockIdGetBlockNumber().
Дата
Msg-id E1nPvQm-000nMp-MY@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/566e1c04df5238464f0c953d9bf09682092a880f

Modified Files
--------------
src/include/storage/block.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Clean up assorted failures under clang's -fsanitize=undefined ch
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Remove some pointless code in block.h.