Skip to content

Commit 33b75d2

Browse files
committed
Fix array.init_elem to use source offset when reading segment data
The interpreter's visitArrayInitElem was ignoring the source offset parameter when reading from the element segment. It used seg->data[i] instead of seg->data[offsetVal + i], meaning it always read from the beginning of the segment regardless of the specified offset. The offset was already correctly computed and used in the bounds check, but not in the actual data access loop. This is now consistent with how visitArrayInitData handles its offset parameter.
1 parent fd5e86e commit 33b75d2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/wasm-interpreter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4597,7 +4597,8 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
45974597
// of references in the table! ArrayNew suffers the same problem.
45984598
// Fixing it will require changing how we represent segments, at least
45994599
// in the interpreter.
4600-
data->values[indexVal + i] = self()->visit(seg->data[i]).getSingleValue();
4600+
data->values[indexVal + i] =
4601+
self()->visit(seg->data[offsetVal + i]).getSingleValue();
46014602
}
46024603
return {};
46034604
}

0 commit comments

Comments
 (0)