From 126e77f2a524447b397bd7cf309ed3186d234a9b Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Mon, 18 Sep 2023 11:15:49 +0100 Subject: [PATCH] Add a default constructor to seqset nodes. (#636) This allows them to exist as fields without invalidating the set. This should make it possible to remove the undefined behaviour in the creation of FrontendSlabMetadata, which is currently created via a reinterpret_cast from a different-typed allocation. FrontendSlabMetadata has a SeqSet::Node field that is in an unspecified state on construction and which is valid only when inserted into a SeqSet. --- src/snmalloc/ds_core/seqset.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/snmalloc/ds_core/seqset.h b/src/snmalloc/ds_core/seqset.h index 600ec07d..e493fbba 100644 --- a/src/snmalloc/ds_core/seqset.h +++ b/src/snmalloc/ds_core/seqset.h @@ -34,6 +34,9 @@ namespace snmalloc constexpr Node(Node* next, Node* prev) : next(next), prev(prev) {} public: + /// Default constructor, creates an invalid node. + constexpr Node() : Node(nullptr, nullptr) {} + void invariant() { SNMALLOC_ASSERT(next != nullptr);