qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] target/tricore: Use unsigned types for bitops in helper_eq_b()
@ 2024-07-23 15:10 Peter Maydell
  2024-07-23 15:37 ` Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Peter Maydell @ 2024-07-23 15:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bastian Koppelmann

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
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/tricore/op_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/tricore/op_helper.c b/target/tricore/op_helper.c
index ba9c4444b39..a0d5a0da1df 100644
--- a/target/tricore/op_helper.c
+++ b/target/tricore/op_helper.c
@@ -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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] target/tricore: Use unsigned types for bitops in helper_eq_b()
  2024-07-23 15:10 [PATCH] target/tricore: Use unsigned types for bitops in helper_eq_b() Peter Maydell
@ 2024-07-23 15:37 ` Philippe Mathieu-Daudé
  2024-07-23 23:28 ` Richard Henderson
  2024-07-29 15:57 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-07-23 15:37 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Bastian Koppelmann

On 23/7/24 17:10, Peter Maydell wrote:
> 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
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   target/tricore/op_helper.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/target/tricore/op_helper.c b/target/tricore/op_helper.c
> index ba9c4444b39..a0d5a0da1df 100644
> --- a/target/tricore/op_helper.c
> +++ b/target/tricore/op_helper.c
> @@ -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().

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] target/tricore: Use unsigned types for bitops in helper_eq_b()
  2024-07-23 15:10 [PATCH] target/tricore: Use unsigned types for bitops in helper_eq_b() Peter Maydell
  2024-07-23 15:37 ` Philippe Mathieu-Daudé
@ 2024-07-23 23:28 ` Richard Henderson
  2024-07-29 15:57 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2024-07-23 23:28 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Bastian Koppelmann

On 7/24/24 01:10, Peter Maydell wrote:
> 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
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   target/tricore/op_helper.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] target/tricore: Use unsigned types for bitops in helper_eq_b()
  2024-07-23 15:10 [PATCH] target/tricore: Use unsigned types for bitops in helper_eq_b() Peter Maydell
  2024-07-23 15:37 ` Philippe Mathieu-Daudé
  2024-07-23 23:28 ` Richard Henderson
@ 2024-07-29 15:57 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2024-07-29 15:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: Bastian Koppelmann

On Tue, 23 Jul 2024 at 16:10, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> 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
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---

I'll take this via my target-arm queue since I'm doing a
pullreq anyway.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-29 15:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-23 15:10 [PATCH] target/tricore: Use unsigned types for bitops in helper_eq_b() Peter Maydell
2024-07-23 15:37 ` Philippe Mathieu-Daudé
2024-07-23 23:28 ` Richard Henderson
2024-07-29 15:57 ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).