apple / foundationdb

FoundationDB - the open source, distributed, transactional key-value store
https://apple.github.io/foundationdb/
Apache License 2.0
14.41k stars 1.31k forks source link

Undefined behaviour analyzer : Member access within misaligned address #1434

Open data-forms-action opened 5 years ago

data-forms-action commented 5 years ago

With the Undefined behaviour analyzer enabled in xcode, I get the following warning when accessing the _valuelength and value members of FDBKeyValue struct following a call to fdb_transaction_get_range() :

Member access within misaligned address 0x0001070c00a6 for type 'const FDBKeyValue' (aka 'const keyvalue'), which requires 4 byte alignment

Is there any way to fix this?

mpilman commented 5 years ago

FDB doesn't align memory correctly. One reason is the Arena allocator that simply returns memory from an blob without any alignment. I started working at this in #1263 but this is much harder than expected...

mpilman commented 5 years ago

btw: if you check the clang documentation (here: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) it seems you could disable the alignment check. This is obviously not a fix but for now this is the best you can do. Eventually we probably should make all data access aligned but this will be a mid-size project and we don't have resource to tackle this right now.