From 4d62116ab2c78a84c65ff7fad8d78087c3c24968 Mon Sep 17 00:00:00 2001 From: anseki Date: Sat, 18 Mar 2017 22:47:19 +0900 Subject: [PATCH] Fix: unsafe initializing Buffer --- lib/readline-sync.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/readline-sync.js b/lib/readline-sync.js index fd85860..4b96b8c 100644 --- a/lib/readline-sync.js +++ b/lib/readline-sync.js @@ -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 + ']',