qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 4/5] target/loongarch/tlb_helper: Fix coverity integer overfl


From: Richard Henderson
Subject: Re: [PATCH 4/5] target/loongarch/tlb_helper: Fix coverity integer overflow error
Date: Tue, 12 Jul 2022 15:47:01 +0530
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1

On 7/12/22 13:31, Xiaojuan Yang wrote:
Replace '1' with '1UL' to fix unintentional integer overflow errors
in tlb_helper file.

Fix coverity CID: 1489759 1489762

Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
---
  target/loongarch/tlb_helper.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/loongarch/tlb_helper.c b/target/loongarch/tlb_helper.c
index bab19c7e05..b300230588 100644
--- a/target/loongarch/tlb_helper.c
+++ b/target/loongarch/tlb_helper.c
@@ -298,7 +298,7 @@ static void invalidate_tlb_entry(CPULoongArchState *env, 
int index)
      } else {
          tlb_ps = FIELD_EX64(env->CSR_STLBPS, CSR_STLBPS, PS);
      }
-    pagesize = 1 << tlb_ps;
+    pagesize = 1UL << tlb_ps;
      mask = MAKE_64BIT_MASK(0, tlb_ps + 1);

This is incorrect, because 1ul is still 32 bits on some hosts, including 
windows64.
More generally, 'ul' is *always* incorrect for qemu.

Much better here to use

    pagesize = MAKE_64BIT_MASK(tlb_ps, 1);

-            tmp0 += (1 << ps);
+            tmp0 += (1UL << ps);

Likewise.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]