[PATCH libdrm] Fix strict aliasing violation in drmHandleEvent

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

 



&buffer[i], e and vblank have been pointers of different types but
refering to the same memory location, thus breaking the strict
aliasing rules.

Fix this by working exclusively with pointers to char.

Signed-off-by: Felix Janda <felix.janda@xxxxxxxxx>
---
 xf86drmMode.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/xf86drmMode.c b/xf86drmMode.c
index 228c6e4..cc776c1 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -885,10 +885,10 @@ int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
 
 int drmHandleEvent(int fd, drmEventContextPtr evctx)
 {
-	char buffer[1024];
-	int len, i;
-	struct drm_event *e;
-	struct drm_event_vblank *vblank;
+	char buffer[1024], *p;
+	int len;
+	struct drm_event e;
+	struct drm_event_vblank vblank;
 
 	/* The DRM read semantics guarantees that we always get only
 	 * complete events. */
@@ -896,39 +896,39 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx)
 	len = read(fd, buffer, sizeof buffer);
 	if (len == 0)
 		return 0;
-	if (len < (int)sizeof *e)
+	if (len < (int)sizeof e)
 		return -1;
 
-	i = 0;
-	while (i < len) {
-		e = (struct drm_event *) &buffer[i];
-		switch (e->type) {
+	p = buffer;
+	while (p < buffer + len) {
+		e = *(struct drm_event *) p;
+		switch (e.type) {
 		case DRM_EVENT_VBLANK:
 			if (evctx->version < 1 ||
 			    evctx->vblank_handler == NULL)
 				break;
-			vblank = (struct drm_event_vblank *) e;
+			vblank = *(struct drm_event_vblank *) p;
 			evctx->vblank_handler(fd,
-					      vblank->sequence,
-					      vblank->tv_sec,
-					      vblank->tv_usec,
-					      U642VOID (vblank->user_data));
+					      vblank.sequence,
+					      vblank.tv_sec,
+					      vblank.tv_usec,
+					      U642VOID (vblank.user_data));
 			break;
 		case DRM_EVENT_FLIP_COMPLETE:
 			if (evctx->version < 2 ||
 			    evctx->page_flip_handler == NULL)
 				break;
-			vblank = (struct drm_event_vblank *) e;
+			vblank = *(struct drm_event_vblank *) p;
 			evctx->page_flip_handler(fd,
-						 vblank->sequence,
-						 vblank->tv_sec,
-						 vblank->tv_usec,
-						 U642VOID (vblank->user_data));
+						 vblank.sequence,
+						 vblank.tv_sec,
+						 vblank.tv_usec,
+						 U642VOID (vblank.user_data));
 			break;
 		default:
 			break;
 		}
-		i += e->length;
+		p += e.length;
 	}
 
 	return 0;
-- 
2.7.3
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux