From 5c4e0c27a7794bcb733ba134f52db0c97db3ff34 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Sat, 8 Jun 2019 03:02:00 +0700 Subject: [PATCH] __emit: Fix undefined behavior Apparently shifting a 32-bit signed value by 31 bits is UB... --- source/compiler/sc1.c | 2 +- source/compiler/sc2.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index c46fbf6e..4ec43515 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -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); diff --git a/source/compiler/sc2.c b/source/compiler/sc2.c index b6110868..b4c97ddd 100644 --- a/source/compiler/sc2.c +++ b/source/compiler/sc2.c @@ -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 {