From 678f5396c91b3d0c7572ed579b0a4fb62b2b4655 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 25 Feb 2011 21:10:21 -0800 Subject: [PATCH] input: Ensure Valuator axes are aligned as needed Let the compiler figure out the correct alignment for the axes data for a valuator by using a union to force double alignment of the initial ValuatorClassRec structure in the allocation. Signed-off-by: Keith Packard Tested-by: Julien Cristau Reviewed-by: Julien Cristau --- dix/devices.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dix/devices.c b/dix/devices.c index 6c0dc42a4..89294aacb 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -1225,6 +1225,7 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, { int i; ValuatorClassPtr valc; + union align_u { ValuatorClassRec valc; double d; } *align; if (!dev) return FALSE; @@ -1237,12 +1238,13 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, numAxes = MAX_VALUATORS; } - valc = (ValuatorClassPtr)calloc(1, sizeof(ValuatorClassRec) + - numAxes * sizeof(AxisInfo) + - numAxes * sizeof(double)); - if (!valc) + align = (union align_u *) calloc(1, sizeof(union align_u) + + numAxes * sizeof(double) + + numAxes * sizeof(AxisInfo)); + if (!align) return FALSE; + valc = &align->valc; valc->sourceid = dev->id; valc->motion = NULL; valc->first_motion = 0; @@ -1251,8 +1253,8 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, valc->numMotionEvents = numMotionEvents; valc->motionHintWindow = NullWindow; valc->numAxes = numAxes; - valc->axes = (AxisInfoPtr)(valc + 1); - valc->axisVal = (double *)(valc->axes + numAxes); + valc->axisVal = (double *)(align + 1); + valc->axes = (AxisInfoPtr)(valc->axisVal + numAxes); if (mode & OutOfProximity) InitProximityClassDeviceStruct(dev);