Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bitfields when writing bits to avoid reading uninitialized memory #168

Open
reventlov opened this issue Aug 7, 2024 · 0 comments
Open
Labels
c++ api enhancement New feature or request

Comments

@reventlov
Copy link
Collaborator

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.

@jasongraffius jasongraffius added the enhancement New feature or request label Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ api enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants