-
-
Couldn't load subscription status.
- Fork 33.6k
lib,src: reset zero fill flag on exception #7093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -973,8 +973,8 @@ Local<Value> WinapiErrnoException(Isolate* isolate, | |
| void* ArrayBufferAllocator::Allocate(size_t size) { | ||
| if (zero_fill_field_ || zero_fill_all_buffers) | ||
| return calloc(size, 1); | ||
| zero_fill_field_ = 1; | ||
| return malloc(size); | ||
| else | ||
| return malloc(size); | ||
|
||
| } | ||
|
|
||
| static bool DomainHasErrorHandler(const Environment* env, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1476,3 +1476,26 @@ assert.equal(SlowBuffer.prototype.offset, undefined); | |
| // Check pool offset after that by trying to write string into the pool. | ||
| assert.doesNotThrow(() => Buffer.from('abc')); | ||
| } | ||
|
|
||
|
|
||
| // Test failed or zero-sized Buffer allocations not affecting typed arrays | ||
| { | ||
| const zeroArray = new Uint32Array(10).fill(0); | ||
|
||
| const sizes = [1e10, 0, 0.1, -1, 'a', undefined, null, NaN]; | ||
| const allocators = [ | ||
| Buffer, | ||
| SlowBuffer, | ||
| Buffer.alloc, | ||
| Buffer.allocUnsafe, | ||
| Buffer.allocUnsafeSlow | ||
| ]; | ||
| for (const allocator of allocators) { | ||
| for (const size of sizes) { | ||
| try { | ||
| allocator(size); | ||
| } catch (e) { | ||
| assert.deepStrictEqual(new Uint32Array(10), zeroArray); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is an extra
ifneeded here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Needed', no, but I added it for symmetry with the check above and because it saves a bounds check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bnoordhuis Ah, that makes sense. Thanks!