__emit: Fix undefined behavior

Apparently shifting a 32-bit signed value by 31 bits is UB...
This commit is contained in:
Daniel_Cortez 2019-06-08 03:02:00 +07:00
parent 991eed9303
commit 5c4e0c27a7
2 changed files with 2 additions and 2 deletions

View File

@ -6314,7 +6314,7 @@ fetchtok:
case tRATIONAL: case tRATIONAL:
if (!allow_nonint) if (!allow_nonint)
goto invalid_token; 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; break;
case tSYMBOL: case tSYMBOL:
sym=findloc(str); sym=findloc(str);

View File

@ -1405,7 +1405,7 @@ static int command(void)
break; break;
} else if (current_token==tRATIONAL) { } else if (current_token==tRATIONAL) {
/* change the first bit to make float negative value */ /* 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); code_idx+=opargs(1);
break; break;
} else { } else {