Module Name:    xsrc
Committed By:   martin
Date:           Sun Mar 22 10:18:19 UTC 2020

Modified Files:
        xsrc/external/mit/xf86-video-ati/dist/src: radeon_accel.c

Log Message:
PR 48569: avoid unaligned access. OK mrg@


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
    xsrc/external/mit/xf86-video-ati/dist/src/radeon_accel.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: xsrc/external/mit/xf86-video-ati/dist/src/radeon_accel.c
diff -u xsrc/external/mit/xf86-video-ati/dist/src/radeon_accel.c:1.2 xsrc/external/mit/xf86-video-ati/dist/src/radeon_accel.c:1.3
--- xsrc/external/mit/xf86-video-ati/dist/src/radeon_accel.c:1.2	Wed Aug 17 00:06:59 2016
+++ xsrc/external/mit/xf86-video-ati/dist/src/radeon_accel.c	Sun Mar 22 10:18:19 2020
@@ -960,7 +960,30 @@ void RADEONCopySwap(uint8_t *dst, uint8_
 	    return;
         }
     case RADEON_HOST_DATA_SWAP_32BIT:
-        {
+	if (((uintptr_t)dst & 1) || ((uintptr_t)src & 1)) {
+	    uint8_t *d = (uint8_t *)dst;
+	    uint8_t *s = (uint8_t *)src;
+	    unsigned int nwords = size >> 2;
+
+	    for (; nwords > 0; --nwords, d+=4, s+=4) {
+	        d[0] = s[3];
+		d[1] = s[2];
+		d[2] = s[1];
+		d[3] = s[0];
+	    }
+	    return;
+        } else if (((uintptr_t)dst & 3) || ((uintptr_t)src & 3)) {
+	    /* copy 16bit wise */
+	    uint16_t *d = (uint16_t *)dst;
+	    uint16_t *s = (uint16_t *)src;
+	    unsigned int nwords = size >> 2;
+
+	    for (; nwords > 0; --nwords, d+=2, s+=2) {
+	        d[0] = ((s[1] >> 8) & 0xff) | ((s[1] & 0xff) << 8);
+	        d[1] = ((s[0] >> 8) & 0xff) | ((s[0] & 0xff) << 8);
+	    }
+	    return;
+	} else {
 	    unsigned int *d = (unsigned int *)dst;
 	    unsigned int *s = (unsigned int *)src;
 	    unsigned int nwords = size >> 2;

Reply via email to