[PATCH] test/input: Fix alignment assertion for doubles

Peter Hutterer peter.hutterer at who-t.net
Wed Feb 19 17:36:45 PST 2014


On Wed, Feb 19, 2014 at 05:16:48PM +0100, Thierry Reding wrote:
> From: Thierry Reding <treding at nvidia.com>
> 
> 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 <treding at nvidia.com>

merged, thanks.

Cheers,
   Peter

> ---
>  test/input.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/test/input.c b/test/input.c
> index 5813e6dc987b..9b5db89919f5 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++;
>      }
> -- 
> 1.8.4.2
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 


More information about the xorg-devel mailing list