Skip to content

Comments

Fix array.init_elem to use source offset when reading segment data#8349

Open
sumleo wants to merge 2 commits intoWebAssembly:mainfrom
sumleo:fix-array-init-elem-offset
Open

Fix array.init_elem to use source offset when reading segment data#8349
sumleo wants to merge 2 commits intoWebAssembly:mainfrom
sumleo:fix-array-init-elem-offset

Conversation

@sumleo
Copy link
Contributor

@sumleo sumleo commented Feb 20, 2026

Summary

  • Fixed a bug in the interpreter's visitArrayInitElem where the source offset parameter was ignored when reading from the element segment
  • The loop used seg->data[i] instead of seg->data[offsetVal + i], always reading from the start of the segment regardless of the specified offset
  • The offset was already correctly computed and validated in the bounds check but not used in the actual data access, now consistent with visitArrayInitData

Test plan

  • Builds successfully
  • All 309 unit tests pass (binaryen-unittests)

sumleo and others added 2 commits February 20, 2026 11:51
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.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant