[PATCH] lib: sbi: Fix sign-extension in sbi_misaligned_load_handler()
Jessica Clarke
jrtc27 at jrtc27.com
Sat Dec 19 23:26:42 EST 2020
> --- a/lib/sbi/sbi_misaligned_ldst.c
> +++ b/lib/sbi/sbi_misaligned_ldst.c
> @@ -128,7 +128,7 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst,
> }
>
> if (!fp)
> - SET_RD(insn, regs, val.data_ulong << shift >> shift);
> + SET_RD(insn, regs, (long)val.data_ulong << shift >> shift);
Left-shifting is undefined behaviour if it sets the sign bit, so a
standards-conforming C compiler is free to ignore the cast entirely
and assume the intermediate left-shifted value is non-negative.
Jess
More information about the opensbi
mailing list