Commit 3aee68b8 authored by Kenton Varda's avatar Kenton Varda Committed by GitHub

Merge pull request #549 from dwrensha/nullish-array-builder

avoid passing invalid reference to Array<T> constructor
parents 7a7c4007 e7524129
......@@ -450,11 +450,17 @@ public:
// check might catch bugs. Probably people should use Vector if they want to build arrays
// without knowing the final size in advance.
KJ_IREQUIRE(pos == endPtr, "ArrayBuilder::finish() called prematurely.");
Array<T> result(reinterpret_cast<T*>(ptr), pos - ptr, *disposer);
const ptrdiff_t size = pos - ptr;
T* start = reinterpret_cast<T*>(ptr);
ptr = nullptr;
pos = nullptr;
endPtr = nullptr;
return result;
if (size == 0) {
// `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 {
......
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