Skip to content

Use correct data length in Array#flat #2058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions std/assembly/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ export class Array<T> {
}

// calculate the byteLength of the resulting backing ArrayBuffer
var byteLength = <usize>size << usize(alignof<valueof<T>>());
const align = alignof<valueof<T>>();
var byteLength = <usize>size << align;
var outBuffer = changetype<ArrayBuffer>(__new(byteLength, idof<ArrayBuffer>()));

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

// ignore null arrays
if (child == 0) continue;
if (!child) continue;

// copy the underlying buffer data to the result buffer
let childDataLength = load<i32>(child, offsetof<T>("byteLength"));
let childDataLength = <usize>load<i32>(child, offsetof<T>("length_")) << align;
memory.copy(
changetype<usize>(outBuffer) + resultOffset,
load<usize>(child, offsetof<T>("dataStart")),
<usize>childDataLength
childDataLength
);

// advance the result length
Expand Down
Loading