Fix bug introduced in 5e1fb1dac5
All checks were successful
Tests / Release [gcc] total: 704, passed: 704
GNU C Compiler (gcc) |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |1|0|1|0|:zzz:
Tests / Release [gcc,aarch64] total: 703, passed: 703
Tests / Coverage total: 702, passed: 702
weaselab/conflict-set/pipeline/head This commit looks good

This commit is contained in:
2024-03-07 17:43:34 -08:00
parent 451ac5b2b6
commit 87dd70c4b6
3 changed files with 20 additions and 9 deletions

View File

@@ -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)

View File

@@ -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 <bool kBegin>
for (;;) {
if ((*self)->partialKeyLen > 0) {
const bool wouldBePresent =
key.size() <= kPartialKeyMaxLenEntryPresent + int(sizeof(Entry));
// Handle an existing partial key
int commonLen = std::min<int>((*self)->partialKeyLen, key.size());
if (wouldBePresent) {
commonLen = std::min(commonLen, kPartialKeyMaxLenEntryPresent);
}
int partialKeyIndex = longestCommonPrefixPartialKey(
(*self)->partialKey, key.data(), commonLen);
if (partialKeyIndex < (*self)->partialKeyLen) {

View File

@@ -549,14 +549,12 @@ template <class ConflictSetImpl> 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
}