From 0a60ba86be393f089d71b2275987b3155c93cb56 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Mon, 18 Sep 2023 10:44:23 +0100 Subject: [PATCH] Add a default constructor to seqset nodes. 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 600ec07df..e493fbba0 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);