diff --git a/CMakeLists.txt b/CMakeLists.txt index df70d49..9a8534d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,10 @@ endif() set(TEST_FLAGS -Wall -Wextra -Wpedantic -Wunreachable-code -UNDEBUG) +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + list(APPEND TEST_FLAGS -Wno-gnu-anonymous-struct -Wno-nested-anon-types) +endif() + include(CTest) if(BUILD_TESTING) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index a99d920..3989160 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -239,9 +239,13 @@ struct Node { int8_t partialKeyLen = 0; int32_t numChildren = 0; Node *parent = nullptr; - uint8_t partialKey[kPartialKeyMaxLenEntryPresent]; - // If not entryPresent, then the partial key might spill over into entry - Entry entry; + union { + uint8_t partialKey[kPartialKeyMaxLenEntryPresent + sizeof(Entry)]; + struct { + uint8_t padding[kPartialKeyMaxLenEntryPresent]; + Entry entry; + }; + }; /* end section that's copied to the next node */ }; @@ -1536,8 +1540,13 @@ template for (;;) { if ((*self)->partialKeyLen > 0) { + const bool wouldBePresent = + key.size() <= kPartialKeyMaxLenEntryPresent + int(sizeof(Entry)); // Handle an existing partial key int commonLen = std::min((*self)->partialKeyLen, key.size()); + if (wouldBePresent) { + commonLen = std::min(commonLen, kPartialKeyMaxLenEntryPresent); + } int partialKeyIndex = longestCommonPrefixPartialKey( (*self)->partialKey, key.data(), commonLen); if (partialKeyIndex < (*self)->partialKeyLen) { diff --git a/Internal.h b/Internal.h index 88635c3..020cfdd 100644 --- a/Internal.h +++ b/Internal.h @@ -549,14 +549,12 @@ template struct TestDriver { } #if DEBUG_VERBOSE && !defined(NDEBUG) if (writes[i].end.len == 0) { - fprintf(stderr, "Write: {%s} -> %d\n", - printable(writes[i].begin).c_str(), - int(writes[i].writeVersion)); + fprintf(stderr, "Write: {%s} -> %" PRId64 "\n", + printable(writes[i].begin).c_str(), writeVersion); } else { - fprintf(stderr, "Write: [%s, %s) -> %d\n", + fprintf(stderr, "Write: [%s, %s) -> %" PRId64 "\n", printable(writes[i].begin).c_str(), - printable(writes[i].end).c_str(), - int(writes[i].writeVersion)); + printable(writes[i].end).c_str(), writeVersion); } #endif }