Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix undefined type-punning when loading/storing words
Despite common practice, type-punning integer types out of buffers is undefined in C and C++. It's both a strict aliasing violation on access, and if the pointer isn't aligned, an alignment violation on cast. Being undefined, the compiler is allowed to arbitrarily miscompile the code when we rely on it. Instead, the two legal ways to pull a uint32_t out of a buffer are to either use memcpy, or load byte by byte and use shifts. In both cases, a good compiler should be smart enough to recognize what we're doing and generate reasonable code. Since there was already fallback code for the latter (for a middle-endian architecture?), I went ahead and switched to that. This change is needed to fix UBSan violations in Chromium.
- Loading branch information