Skip to content

Commit

Permalink
__emit: Fix undefined behavior
Browse files Browse the repository at this point in the history
Apparently shifting a 32-bit signed value by 31 bits is UB
  • Loading branch information
Daniel-Cortez committed Jun 7, 2019
1 parent 991eed9 commit bad16ae
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/compiler/sc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -6314,7 +6314,7 @@ static int SC_FASTCALL emit_param_any_internal(emit_outval *p,int expected_tok,
case tRATIONAL:
if (!allow_nonint)
goto invalid_token;
p->value.ucell=(ucell)(negate ? (val|((cell)1 << (PAWN_CELL_SIZE-1))) : val);
p->value.ucell=(negate ? ((ucell)val|((ucell)1 << (PAWN_CELL_SIZE-1))) : (ucell)val);
break;
case tSYMBOL:
sym=findloc(str);
Expand Down
2 changes: 1 addition & 1 deletion source/compiler/sc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ static int command(void)
break;
} else if (current_token==tRATIONAL) {
/* change the first bit to make float negative value */
outval(val|((cell)1 << (PAWN_CELL_SIZE-1)),FALSE);
outval(val|(cell)((ucell)1 << (PAWN_CELL_SIZE-1)),FALSE);
code_idx+=opargs(1);
break;
} else {
Expand Down

0 comments on commit bad16ae

Please sign in to comment.