Fix: unsafe initializing Buffer

This commit is contained in:
anseki 2017-03-18 22:47:19 +09:00
parent 39e95b7ca7
commit 4d62116ab2

View file

@ -364,13 +364,9 @@ function _readlineSync(options) {
return;
}
// https://github.com/nodejs/node/issues/4660
// https://github.com/nodejs/node/pull/4682
if (Buffer.alloc) {
buffer = Buffer.alloc((reqSize = options.keyIn ? 1 : options.bufferSize));
} else {
buffer = new Buffer((reqSize = options.keyIn ? 1 : options.bufferSize));
}
reqSize = options.keyIn ? 1 : options.bufferSize;
// Check `allocUnsafe` to make sure of the new API.
buffer = Buffer.allocUnsafe && Buffer.alloc ? Buffer.alloc(reqSize) : new Buffer(reqSize);
if (options.keyIn && options.limit) {
limit = new RegExp('[^' + options.limit + ']',