From aee861c0099addb22752386e4ea6809b2ff2a76f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 9 Dec 2019 09:39:36 +0100 Subject: [PATCH] util/AllocatedArray: copy constructor copies "nulled" state --- src/util/AllocatedArray.hxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util/AllocatedArray.hxx b/src/util/AllocatedArray.hxx index c37a3f992..21fe668ef 100644 --- a/src/util/AllocatedArray.hxx +++ b/src/util/AllocatedArray.hxx @@ -62,11 +62,13 @@ public: assert(size() == 0 || buffer.data != nullptr); } - explicit AllocatedArray(const AllocatedArray &other) noexcept - :buffer{new T[other.buffer.size], other.buffer.size} { - assert(size() == 0 || buffer.data != nullptr); + explicit AllocatedArray(const AllocatedArray &other) noexcept { assert(other.size() == 0 || other.buffer.data != nullptr); + if (other == nullptr) + return; + + buffer = {new T[other.buffer.size], other.buffer.size}; std::copy_n(other.buffer.data, buffer.size, buffer.data); }