Skip to content

Commit 2063f28

Browse files
Validate the number of block parameters
1 parent e24e3cd commit 2063f28

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed
Binary file not shown.

Sources/WasmKit/Translator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
427427

428428
mutating func preserveLocalsOnStack(depth: Int) -> [(source: LocalIndex, to: VReg)] {
429429
var copies: [(source: LocalIndex, to: VReg)] = []
430-
for offset in 0..<depth {
430+
for offset in 0..<min(depth, self.values.count) {
431431
let valueIndex = self.values.count - 1 - offset
432432
let value = self.values[valueIndex]
433433
guard case .local(let type, let localIndex) = value else { continue }
@@ -439,7 +439,7 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
439439

440440
mutating func preserveConstsOnStack(depth: Int) -> [(source: VReg, to: VReg)] {
441441
var copies: [(source: VReg, to: VReg)] = []
442-
for offset in 0..<depth {
442+
for offset in 0..<min(depth, self.values.count) {
443443
let valueIndex = self.values.count - 1 - offset
444444
let value = self.values[valueIndex]
445445
guard case .const(let type, let index) = value else { continue }

0 commit comments

Comments
 (0)