summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2011-02-25 21:10:21 -0800
committerKeith Packard <keithp@keithp.com>2011-02-25 21:25:25 -0800
commit678f5396c91b3d0c7572ed579b0a4fb62b2b4655 (patch)
tree5edf43acc1d5109677f722bda6d412f5e4c46ce0
parentdc8f52e77f51b6fa8908d9611c3f7e3cfbbaf2d1 (diff)
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 <keithp@keithp.com> Tested-by: Julien Cristau <jcristau@debian.org> Reviewed-by: Julien Cristau <jcristau@debian.org>
-rw-r--r--dix/devices.c14
1 files 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);