]> zoso.dev Git - buffer.git/commitdiff
more robust check for invalid arguments to copy()
authorFeross Aboukhadijeh <feross@feross.org>
Fri, 16 Feb 2018 05:56:28 +0000 (21:56 -0800)
committerFeross Aboukhadijeh <feross@feross.org>
Fri, 16 Feb 2018 05:56:28 +0000 (21:56 -0800)
index.js

index b2ace856dfe8278fdde13c245a2b0db3dbc65c68..0e45b2ad69ff98c4b2a4aa782d8a2b1d89832437 100644 (file)
--- a/index.js
+++ b/index.js
@@ -1465,9 +1465,7 @@ 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 (!Buffer.isBuffer(target)) 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