Skip to content
Snippets Groups Projects
Commit 43a36202 authored by Vladislav Shpilevoy's avatar Vladislav Shpilevoy
Browse files

bit: fix unaligned memory access and UB bit shift


Lib/bit library in some functions dereferenced a byte array as a
pointer at uint64 or uint32. It led to unaligned memory access,
when the array didn't have the needed alignment. That made clang
'alignment' sanitizer crazy.

Also there were places, where bitwise shift was done for the type
size. For example, a uint32 number was allowed to make 32 bit
shift in both sides. This is undefined behaviour.

The patch fixes these UBs. Bitwise shift of too long size is
banned. Unaligned access is fixed in some places by changing
uint64 to uint8, when it is possible without perf loss. And in the
others by using explicitly specified unaligned load. So it works
the same, but the sanitizer is aware of that.

Part of #4609

Reviewed-by: default avatarAleksandr Lyapunov <alyapunov@tarantool.org>
Reviewed-by: default avatarTimur Safin <tsafin@tarantool.org>
parent 8b5657aa
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment