Commit c7440fe8 authored by Kenton Varda's avatar Kenton Varda Committed by GitHub

Merge pull request #578 from capnproto/revert-549-nullish-array-builder

Revert "avoid passing invalid reference to Array<T> constructor"
parents d067d620 9842ff91
...@@ -450,17 +450,11 @@ public: ...@@ -450,17 +450,11 @@ public:
// check might catch bugs. Probably people should use Vector if they want to build arrays // check might catch bugs. Probably people should use Vector if they want to build arrays
// without knowing the final size in advance. // without knowing the final size in advance.
KJ_IREQUIRE(pos == endPtr, "ArrayBuilder::finish() called prematurely."); KJ_IREQUIRE(pos == endPtr, "ArrayBuilder::finish() called prematurely.");
const ptrdiff_t size = pos - ptr; Array<T> result(reinterpret_cast<T*>(ptr), pos - ptr, *disposer);
T* start = reinterpret_cast<T*>(ptr);
ptr = nullptr; ptr = nullptr;
pos = nullptr; pos = nullptr;
endPtr = nullptr; endPtr = nullptr;
if (size == 0) { return result;
// `disposer` possibly does not point to anything, so don't pass `*disposer` to `Array`.
return Array<T>();
} else {
return Array<T>(start, size, *disposer);
}
} }
inline bool isFull() const { inline bool isFull() const {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment