Skip to content

Commit 559f5e9

Browse files
committed
move type validation before allocation
1 parent ba806ae commit 559f5e9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/buffer.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,16 +639,19 @@ Buffer.concat = function concat(list, length) {
639639
}
640640

641641
validateOffset(length, 'length');
642-
const buffer = allocate(length);
643-
let pos = 0;
644642
for (let i = 0; i < list.length; i++) {
645-
const buf = list[i];
646-
if (!isUint8Array(buf)) {
643+
if (!isUint8Array(list[i])) {
647644
// TODO(BridgeAR): This should not be of type ERR_INVALID_ARG_TYPE.
648645
// Instead, find the proper error code for this.
649646
throw new ERR_INVALID_ARG_TYPE(
650-
`list[${i}]`, ['Buffer', 'Uint8Array'], buf);
647+
`list[${i}]`, ['Buffer', 'Uint8Array'], list[i]);
651648
}
649+
}
650+
651+
const buffer = allocate(length);
652+
let pos = 0;
653+
for (let i = 0; i < list.length; i++) {
654+
const buf = list[i];
652655
if (pos + buf.length > length) {
653656
TypedArrayPrototypeSet(buffer,
654657
TypedArrayPrototypeSlice(buf, 0, length - pos),

0 commit comments

Comments
 (0)