diff --git a/lib/buffer.js b/lib/buffer.js index 398357c6845568..43d9d4d5822bd7 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -278,7 +278,8 @@ function assertSize(size) { Buffer.alloc = function alloc(size, fill, encoding) { assertSize(size); if (fill !== undefined && fill !== 0 && size > 0) { - return _fill(createUnsafeBuffer(size), fill, encoding); + const buf = createUnsafeBuffer(size); + return _fill(buf, fill, 0, buf.length, encoding); } return new FastBuffer(size); }; diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index daab9c9edc12e9..f89e25fdbb2f92 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -1039,3 +1039,10 @@ common.expectsError(() => { code: 'ERR_INVALID_ARG_VALUE', type: TypeError }); + +common.expectsError(() => { + Buffer.alloc(40, 'x', 20); +}, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError +});