diff --git a/ConflictSet.cpp b/ConflictSet.cpp index db5e24b..f469124 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -1577,7 +1577,7 @@ bool checkRangeRead(Node *n, std::span begin, // Returns a pointer to the newly inserted node. Caller must set // `entryPresent`, `entry` fields and `maxVersion` on the result. The search // path of the result's parent will have `maxVersion` at least `writeVersion` as -// a postcondition. +// a postcondition. Nodes along the search path may be invalidated. template [[nodiscard]] Node *insert(Node **self, std::span key, int64_t writeVersion, NodeAllocators *allocators, @@ -1704,6 +1704,7 @@ void addWriteRange(Node *&root, int64_t oldestVersion, return addPointWrite(root, oldestVersion, begin, writeVersion, allocators, impl); } + const bool beginIsPrefix = lcp == int(begin.size()); auto remaining = begin.subspan(0, lcp); auto *n = root; @@ -1772,8 +1773,9 @@ void addWriteRange(Node *&root, int64_t oldestVersion, } endNode->entry.rangeVersion = writeVersion; - if (insertedEnd) { - // beginNode may have been invalidated + if (beginIsPrefix && insertedEnd) { + // beginNode may have been invalidated when inserting end. TODO can we do + // better? beginNode = insert(useAsRoot, begin, writeVersion, allocators, impl); assert(beginNode->entryPresent); }