diff options
author | Keyhan Vakil <kvakil@sylph.kvakil.me> | 2022-08-06 07:01:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-06 07:01:22 +0300 |
commit | 760ecc9c75a3bbafab340b24e43e3bfbdc4a78fc (patch) | |
tree | dcb6721f374ac6722c03e14c65aa0daa5e1dd4ab /src/util.h | |
parent | 90c758c59e6c4f3b2300270a904792a471404db3 (diff) |
src: prevent copying ArrayBufferViewContents
It is error-prone to copy or heap-allocate `ArrayBufferViewContents`,
because you might accidentally cause it to exceed the lifetime of its
argument. Let's make it impossible to do so. Fortunately we were not
doing so anywhere already, so this diff is purely defensive.
Refs: https://github.com/nodejs/node/pull/44079#discussion_r934376046
PR-URL: https://github.com/nodejs/node/pull/44091
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h index 290862e21c1..3f58dd0a86d 100644 --- a/src/util.h +++ b/src/util.h @@ -498,6 +498,9 @@ class ArrayBufferViewContents { public: ArrayBufferViewContents() = default; + ArrayBufferViewContents(const ArrayBufferViewContents&) = delete; + void operator=(const ArrayBufferViewContents&) = delete; + explicit inline ArrayBufferViewContents(v8::Local<v8::Value> value); explicit inline ArrayBufferViewContents(v8::Local<v8::Object> value); explicit inline ArrayBufferViewContents(v8::Local<v8::ArrayBufferView> abv); @@ -507,6 +510,13 @@ class ArrayBufferViewContents { inline size_t length() const { return length_; } private: + // Declaring operator new and delete as deleted is not spec compliant. + // Therefore, declare them private instead to disable dynamic alloc. + void* operator new(size_t size); + void* operator new[](size_t size); + void operator delete(void*, size_t); + void operator delete[](void*, size_t); + T stack_storage_[kStackStorageSize]; T* data_ = nullptr; size_t length_ = 0; |