From 31b0be69e5eea3d1c82d6610bd37bbdb4dca779c Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Wed, 19 Feb 2014 17:16:48 +0100 Subject: [PATCH] test/input: Fix alignment assertion for doubles The code previously tried to compute the offset of a field in the valuator by subtracting the address of the valuator from the _value_ of the field (rather than the field's address). The correct way to do it would have been (note the &'s): assert(((void *) &v->axisVal - (void *) v) % sizeof(double) == 0); assert(((void *) &v->axes - (void *) v) % sizeof(double) == 0); That's essentially what the offsetof() macro does. Using offsetof() has the added benefit of not using void pointer arithmetic and therefore silencing a warning on some compilers. Signed-off-by: Thierry Reding Signed-off-by: Peter Hutterer --- test/input.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/input.c b/test/input.c index 5813e6dc9..9b5db8991 100644 --- a/test/input.c +++ b/test/input.c @@ -1390,8 +1390,8 @@ dix_valuator_alloc(void) assert(v->numAxes == num_axes); #if !defined(__i386__) && !defined(__m68k__) && !defined(__sh__) /* must be double-aligned on 64 bit */ - assert(((void *) v->axisVal - (void *) v) % sizeof(double) == 0); - assert(((void *) v->axes - (void *) v) % sizeof(double) == 0); + assert(offsetof(struct _ValuatorClassRec, axisVal) % sizeof(double) == 0); + assert(offsetof(struct _ValuatorClassRec, axes) % sizeof(double) == 0); #endif num_axes++; }