Skip to content

Commit

Permalink
prevent ill-formed from int2char
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaradc committed Jun 16, 2023
1 parent 17694fc commit ec0f81b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion brili.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ function evalInstr(instr: bril.Instruction, state: State): Action {

case "int2char": {
let i = getInt(instr, state.env, 0);
if(i > 1114111 || i < 0) {
if (i > 1114111 || i < 0 || (55295 < i && i < 57344)) {
throw error(`value ${i} cannot be converted to char`);
}
let val = String.fromCodePoint(Number(i));
Expand Down
2 changes: 1 addition & 1 deletion test/interp-error/char-error/badconversion.bril
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@main {
i: int = const 1114112;
i: int = const 56193;

c: char = int2char i;

Expand Down
2 changes: 1 addition & 1 deletion test/interp-error/char-error/badconversion.err
Original file line number Diff line number Diff line change
@@ -1 +1 @@
error: value 1114112 cannot be converted to char
error: value 56193 cannot be converted to char

0 comments on commit ec0f81b

Please sign in to comment.