From: Volker Mische Date: Fri, 19 Jan 2018 14:40:25 +0000 (+0100) Subject: Throw error when no buffer is given for `copy()` X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=c404fd1492020a6137c525c90a08cda7e30b4903;p=buffer.git Throw error when no buffer is given for `copy()` --- diff --git a/index.js b/index.js index 2584ee7..63479f4 100644 --- a/index.js +++ b/index.js @@ -1445,6 +1445,9 @@ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (target === undefined) { + throw new TypeError('argument should be a Buffer') + } if (!start) start = 0 if (!end && end !== 0) end = this.length if (targetStart >= target.length) targetStart = target.length diff --git a/test/node/test-buffer-alloc.js b/test/node/test-buffer-alloc.js index d346521..3f04b3e 100644 --- a/test/node/test-buffer-alloc.js +++ b/test/node/test-buffer-alloc.js @@ -935,11 +935,11 @@ var ps = Buffer.poolSize; Buffer.poolSize = 0; assert(Buffer.allocUnsafe(1).parent instanceof ArrayBuffer); Buffer.poolSize = ps; - +*/ // Test Buffer.copy() segfault assert.throws(() => Buffer.allocUnsafe(10).copy(), /TypeError: argument should be a Buffer/); - +/* var regErrorMsg = new RegExp('The first argument must be one of type string, Buffer, ' + 'ArrayBuffer, Array, or Array-like Object\\.');