Use bitfields when writing `bits` to avoid reading uninitialized memory
Open
c++ api
enhancement
- Dominant language
- Python
- Stars
- 92
- Forks
- 30
- PR merge metrics
- No merged PRs in 30d
Description
Right now, Emboss uses read-modify-write (RMW) for any values inside `bits`, which means that writing to a field within `bits` can cause undefined behavior (UB) if the underlying buffer was not initialized.
It should be possible, at least on Clang, GCC, and MSVC, to write through a (C++) bitfield without doing the RMW at the C++ level, and therefore avoiding UB.
Note that the exact layout of C++ bitfields is implementation-defined, and there are also potential issues with strict aliasing violations, but for specific compilers it should be doable.
Contributor guide
Assessment
This issue has not been assessed yet.