[PATCH] dix: Really align valuators on doubles.

Peter Hutterer peter.hutterer at who-t.net
Tue May 17 20:30:44 PDT 2011


678f5396c91b3d0c7572ed579b0a4fb62b2b4655 introduced alignment on doubles for
the valuators, 419a27b5219a739f2fbd50cc96a1b54c469e4a88 blindly copied it.
Alas, it doesn't actually align on doubles.

678f5396c works on 64 bit because it switched the assignments of axes and
axisVals around to have axisVals always point to the first byte after the
struct. On 64 bit ValuatorClassRec is size 96, so we're aligned anyway.
All the machines that triggered the previous bug were 64 bit machines.

On 32 bit server 1.10, ValuatorClassRec is size 52 and no-one noticed except
one test case that inconveniently kept blowing up.

Replace with a union that is forced to N * sizeof(double) where N is defined
by the current size of ValuatorClassRec.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 dix/devices.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/dix/devices.c b/dix/devices.c
index 9a4498b..367dccd 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1234,8 +1234,12 @@ ValuatorClassPtr
 AllocValuatorClass(ValuatorClassPtr src, int numAxes)
 {
     ValuatorClassPtr v;
+    const int sz_dbl = sizeof(double);
     /* force alignment with double */
-    union align_u { ValuatorClassRec valc; double d; } *align;
+    union align_u {
+        ValuatorClassRec valc;
+        double d[(sizeof(ValuatorClassRec) + sz_dbl - 1)/sz_dbl];
+    } *align;
     int size;
 
     size = sizeof(union align_u) + numAxes * (sizeof(double) + sizeof(AxisInfo));
-- 
1.7.4.4



More information about the xorg-devel mailing list