Skip to content

Commit 5dce4e4

Browse files
authored
fix: Use correct data length in Array#flat (#2058)
1 parent ba270a8 commit 5dce4e4

File tree

4 files changed

+1138
-615
lines changed

4 files changed

+1138
-615
lines changed

std/assembly/array.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ export class Array<T> {
473473
}
474474

475475
// calculate the byteLength of the resulting backing ArrayBuffer
476-
var byteLength = <usize>size << usize(alignof<valueof<T>>());
476+
const align = alignof<valueof<T>>();
477+
var byteLength = <usize>size << align;
477478
var outBuffer = changetype<ArrayBuffer>(__new(byteLength, idof<ArrayBuffer>()));
478479

479480
// create the return value and initialize it
@@ -492,14 +493,14 @@ export class Array<T> {
492493
let child = load<usize>(ptr + (<usize>i << alignof<T>()));
493494

494495
// ignore null arrays
495-
if (child == 0) continue;
496+
if (!child) continue;
496497

497498
// copy the underlying buffer data to the result buffer
498-
let childDataLength = load<i32>(child, offsetof<T>("byteLength"));
499+
let childDataLength = <usize>load<i32>(child, offsetof<T>("length_")) << align;
499500
memory.copy(
500501
changetype<usize>(outBuffer) + resultOffset,
501502
load<usize>(child, offsetof<T>("dataStart")),
502-
<usize>childDataLength
503+
childDataLength
503504
);
504505

505506
// advance the result length

0 commit comments

Comments
 (0)