google / google/emboss

Use bitfields when writing `bits` to avoid reading uninitialized memory

Open
#168 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.