target/tricore: Use unsigned types for bitops in helper_eq_b()
PATCH 1/1 target/tricore: Use unsigned types for bitops in helper_eq_b()
Coverity points out that in helper_eq_b() we have an int32_t 'msk' and we end up shifting into its sign bit. This is OK for QEMU because we use -fwrapv to give this well defined semantics, but when you look at what this function is doing it's doing bit operations, so we should be using an unsigned variable anyway. This also matches the return type of the function.
Make 'ret' and 'msk' uint32_t.
Resolves: Coverity CID 1547758
--- target/tricore/op_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/tricore/op_helper.c +2 -2
@@ -1505,8 +1505,8 @@ uint32_t helper_sub_h(CPUTriCoreState *env, target_ulong r1, target_ulong r2)uint32_t helper_eq_b (target_ulong r1,target_ulong r2) { -int32_t ret; -int32_t i, msk; +uint32_t ret, msk; +int32_t i; ret =0 ; msk =0xff ;
Signature · 1 line
2.34.1
Quoted 20 lines · Peter Maydell
Coverity points out that in
helper_eq_b()we have anint32_t'msk' and we end up shifting into its sign bit. This is OK for QEMU because we use -fwrapv to give this well defined semantics, but when you look at what this function is doing it's doing bit operations, so we should be using an unsigned variable anyway. This also matches the return type of the function.Make 'ret' and 'msk'
uint32_t.Resolves: Coverity CID 1547758
Signed-off-by Peter Maydell <[email protected]>--- target/tricore/op_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/tricore/op_helper.c +0
-0
target/tricore/op_helper.c uint32_t helper_sub_h(CPUTriCoreState *env, target_ulong r1, target_ulong r2) · line 1509
Quoted 7 lines
target/tricore/op_helper.c +2
-2@@ -1505,8 +1505,8 @@ uint32_t helper_sub_h(CPUTriCoreState *env, target_ulong r1, target_ulong r2)uint32_t helper_eq_b (target_ulong r1,target_ulong r2) { -int32_t ret; -int32_t i, msk; +uint32_t ret, msk; +int32_t i;
We could even reduce 'i' scope to the for().
Quoted 7 lines · Peter Maydell
Coverity points out that in
helper_eq_b()we have anint32_t'msk' and we end up shifting into its sign bit. This is OK for QEMU because we use -fwrapv to give this well defined semantics, but when you look at what this function is doing it's doing bit operations, so we should be using an unsigned variable anyway. This also matches the return type of the function.
Quoted 7 lines
Make 'ret' and 'msk'
uint32_t.Resolves: Coverity CID 1547758
Signed-off-by Peter Maydell<[email protected]>--- target/tricore/op_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
r~
Quoted 8 lines · Peter Maydell
Coverity points out that in
helper_eq_b()we have anint32_t'msk' and we end up shifting into its sign bit. This is OK for QEMU because we use -fwrapv to give this well defined semantics, but when you look at what this function is doing it's doing bit operations, so we should be using an unsigned variable anyway. This also matches the return type of the function.
Quoted 5 lines
Make 'ret' and 'msk'
uint32_t.Resolves: Coverity CID 1547758
Signed-off-by Peter Maydell <[email protected]>---
I'll take this via my target-arm queue since I'm doing a pullreq anyway.
thanks
-- PMM