Skip to content

Commit 1898304

Browse files
committed
use TypedArrayPrototypeGetByteLength
1 parent 559f5e9 commit 1898304

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/buffer.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,15 +621,16 @@ Buffer.concat = function concat(list, length) {
621621
throw new ERR_INVALID_ARG_TYPE(
622622
`list[${i}]`, ['Buffer', 'Uint8Array'], buf);
623623
}
624-
length += buf.length;
624+
length += TypedArrayPrototypeGetByteLength(buf);
625625
}
626626

627627
const buffer = allocate(length);
628628
let pos = 0;
629629
for (let i = 0; i < list.length; i++) {
630630
const buf = list[i];
631+
const bufLength = TypedArrayPrototypeGetByteLength(buf);
631632
TypedArrayPrototypeSet(buffer, buf, pos);
632-
pos += buf.length;
633+
pos += bufLength;
633634
}
634635

635636
if (pos < length) {
@@ -652,15 +653,16 @@ Buffer.concat = function concat(list, length) {
652653
let pos = 0;
653654
for (let i = 0; i < list.length; i++) {
654655
const buf = list[i];
655-
if (pos + buf.length > length) {
656+
const bufLength = TypedArrayPrototypeGetByteLength(buf);
657+
if (pos + bufLength > length) {
656658
TypedArrayPrototypeSet(buffer,
657659
TypedArrayPrototypeSlice(buf, 0, length - pos),
658660
pos);
659661
pos = length;
660662
break;
661663
}
662664
TypedArrayPrototypeSet(buffer, buf, pos);
663-
pos += buf.length;
665+
pos += bufLength;
664666
}
665667

666668
// Note: `length` is always equal to `buffer.length` at this point

0 commit comments

Comments
 (0)