diff mbox series

[xf86-video-intel,2/7] sna: Don't memcpy() between different types

Message ID 20250210175836.30984-3-ville.syrjala@linux.intel.com (mailing list archive)
State New
Headers show
Series Silence warns and fix up sprite stuff | expand

Commit Message

Ville Syrjälä Feb. 10, 2025, 5:58 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Currently we're doing a blind memcpy() from a DDXPointRec
into the beginning of a BoxRec. While this apparently works
it's quite dodgy. Get rid of the memcpy() and simply assign
each member by hand.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 src/sna/fb/fbspan.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/src/sna/fb/fbspan.c b/src/sna/fb/fbspan.c
index 18136c200458..0700d8811efe 100644
--- a/src/sna/fb/fbspan.c
+++ b/src/sna/fb/fbspan.c
@@ -37,14 +37,16 @@  fbFillSpans(DrawablePtr drawable, GCPtr gc,
 {
 	DBG(("%s x %d\n", __FUNCTION__, n));
 	while (n--) {
-		BoxRec box;
-
-		memcpy(&box, pt, sizeof(box));
-		box.x2 = box.x1 + *width++;
-		box.y2 = box.y1 + 1;
+		BoxRec box = {
+			.x1 = pt->x,
+			.y1 = pt->y,
+			.x2 = pt->x + *width,
+			.y2 = pt->y + 1,
+		};
 
 		/* XXX fSorted */
 		fbDrawableRun(drawable, gc, &box, fbFillSpan, NULL);
+		width++;
 		pt++;
 	}
 }
@@ -90,12 +92,14 @@  fbSetSpans(DrawablePtr drawable, GCPtr gc,
 
 	data.src = src;
 	while (n--) {
-		BoxRec box;
+		BoxRec box = {
+			.x1 = pt->x,
+			.y1 = pt->y,
+			.x2 = pt->x + *width,
+			.y2 = pt->y + 1,
+		};
 
-		memcpy(&box, pt, sizeof(box));
 		data.pt = *pt;
-		box.x2 = box.x1 + *width;
-		box.y2 = box.y1 + 1;
 
 		fbDrawableRun(drawable, gc, &box, fbSetSpan, &data);