Skip to content

Commit 26715dd

Browse files
WAT: Check bounds of signed integer literals
1 parent 6f28ac1 commit 26715dd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sources/WAT/Parser.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ internal struct Parser {
9494
}
9595
switch sign {
9696
case .plus, nil: return fromBitPattern(value)
97-
case .minus: return fromBitPattern(~value &+ 1)
97+
case .minus:
98+
let casted = fromBitPattern(~value &+ 1)
99+
guard casted <= 0 else {
100+
throw WatParserError("invalid literal \(token.text(from: lexer))", location: token.location(in: lexer))
101+
}
102+
return casted
98103
}
99104
}
100105

0 commit comments

Comments
 (0)