-
Notifications
You must be signed in to change notification settings - Fork 29k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buffer: don't set zero fill for zero-length buffer
Instantiating a Buffer of length zero would set the kNoZeroFill flag to true but never actually call ArrayBuffer::Allocator(). Which means the flag was never set back to false. The result was that the next allocation would unconditionally not be zero filled. Add test to ensure Uint8Array's are zero-filled after creating a Buffer of length zero. This test may falsely succeed, but will not falsely fail. Fix: #2930 PR-URL: #2931 Reviewed-By: Rod Vagg <rod@vagg.org>
- Loading branch information
1 parent
e0c3d2a
commit 0a329d2
Showing
2 changed files
with
33 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
|
||
function testUint8Array(ui) { | ||
const length = ui.length; | ||
for (let i = 0; i < length; i++) | ||
if (ui[i] !== 0) return false; | ||
return true; | ||
} | ||
|
||
|
||
for (let i = 0; i < 100; i++) { | ||
new Buffer(0); | ||
let ui = new Uint8Array(65); | ||
assert.ok(testUint8Array(ui), 'Uint8Array is not zero-filled'); | ||
} |
0a329d2
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.
The title of this PR should be "don't set no-zero-fill for zero-length buffer".
Not a fan of negative variable names.