Skip to contentSkip to conversation

hw/display/framebuffer: Add cast to force 64x64 multiply

PATCH In review Peter Maydell 2 participants 3 messages Jul 10, 2025 – Jul 21, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/display/framebuffer: Add cast to force 64x64 multiply

In framebuffer_update_display(), Coverity complains because we multiply two values of type 'int' (which will be done as a 32x32 multiply and so in theory might overflow) and then add the result to a ram_addr_t, which can be 64 bits.

4GB framebuffers are not plausible anyway, but keep Coverity happy by adding casts which force these multiplies to be done as 64x64.

Coverity: CID 1487248

---
This is one of those ones where I'm on the fence about sticking in the cast vs just marking it a false-positive.

---
 hw/display/framebuffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/display/framebuffer.c +3 -3
index 4485aa335bb..b4296e8a33e 100644
@@ -95,9 +95,9 @@ void framebuffer_update_display(
     }
     first = -1;
 
-    addr += i * src_width;
-    src += i * src_width;
-    dest += i * dest_row_pitch;
+    addr += (uint64_t)i * src_width;
+    src += (uint64_t)i * src_width;
+    dest += (uint64_t)i * dest_row_pitch;
 
     snap = memory_region_snapshot_and_clear_dirty(mem, addr, src_width * rows,
                                                   DIRTY_MEMORY_VGA);
Signature · 1 line
2.43.0
#1 lore raw

Ping -- any opinions/review about this one?

-- PMM

Quoted 35 lines · Peter Maydell

In framebuffer_update_display(), Coverity complains because we multiply two values of type 'int' (which will be done as a 32x32 multiply and so in theory might overflow) and then add the result to a ram_addr_t, which can be 64 bits.

4GB framebuffers are not plausible anyway, but keep Coverity happy by adding casts which force these multiplies to be done as 64x64.

Coverity: CID 1487248

---
This is one of those ones where I'm on the fence about sticking in the cast vs just marking it a false-positive.

---
 hw/display/framebuffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/display/framebuffer.c +3 -3
index 4485aa335bb..b4296e8a33e 100644
@@ -95,9 +95,9 @@ void framebuffer_update_display(
     }
     first = -1;
 
-    addr += i * src_width;
-    src += i * src_width;
-    dest += i * dest_row_pitch;
+    addr += (uint64_t)i * src_width;
+    src += (uint64_t)i * src_width;
+    dest += (uint64_t)i * dest_row_pitch;
 
     snap = memory_region_snapshot_and_clear_dirty(mem, addr, src_width * rows,
                                                   DIRTY_MEMORY_VGA);
#2 lore raw
Quoted 39 lines · Peter Maydell

Ping -- any opinions/review about this one?

-- PMM

Quoted 33 lines · Peter Maydell

In framebuffer_update_display(), Coverity complains because we multiply two values of type 'int' (which will be done as a 32x32 multiply and so in theory might overflow) and then add the result to a ram_addr_t, which can be 64 bits.

4GB framebuffers are not plausible anyway, but keep Coverity happy by adding casts which force these multiplies to be done as 64x64.

Coverity: CID 1487248

---
This is one of those ones where I'm on the fence about sticking in the cast vs just marking it a false-positive.

---
 hw/display/framebuffer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/display/framebuffer.c +3 -3
index 4485aa335bb..b4296e8a33e 100644
@@ -95,9 +95,9 @@ void framebuffer_update_display(
     }
     first = -1;
 
-    addr += i * src_width;
-    src += i * src_width;
-    dest += i * dest_row_pitch;
+    addr += (uint64_t)i * src_width;
+    src += (uint64_t)i * src_width;
+    dest += (uint64_t)i * dest_row_pitch;
 
Quoted 3 lines

hw/display/framebuffer.c void framebuffer_update_display( · line 103

Quoted 2 lines
hw/display/framebuffer.c +0 -0
     snap = memory_region_snapshot_and_clear_dirty(mem, addr, src_width * rows,
                                                   DIRTY_MEMORY_VGA);