[PATCH 05/10] fb: Be screechingly correct about interpreting a pointer as integer

Mark Kettenis mark.kettenis at xs4all.nl
Mon Mar 10 09:16:30 PDT 2014


> From: Adam Jackson <ajax at redhat.com>
> Date: Mon, 10 Mar 2014 11:04:29 -0400
> 
> fbblt.c: In function 'fbSetBltOdd':
> fbblt.c:719:19: error: cast from pointer to integer of different size
> [-Werror=pointer-to-int-cast]
>      srcAdjust = (((int) stip) & (FB_MASK >> 3));
> 
> Probably this would have been broken on big-endian.

Actually the code is fine.  Truncation of the pointer isn't a problem
as we're just looking at the bottom few diffs.  Nevertheless casting
stip to uintptr_t shouldn't hurt.  However, srcAdjust can remain an
int, saving a bit of stack space and keeping things a bit more
consistent with strideAdjust being an int as well.

Should add an include for <stdint.h> unless you add it to "fb.h" or
can convince me it's reliably included through some other route.

> Signed-off-by: Adam Jackson <ajax at redhat.com>
> ---
>  fb/fbblt.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fb/fbblt.c b/fb/fbblt.c
> index 8c32b65..37bd912 100644
> --- a/fb/fbblt.c
> +++ b/fb/fbblt.c
> @@ -710,13 +710,13 @@ fbSetBltOdd(FbStip * stip,
>              FbStride * strideEven,
>              FbStride * strideOdd, int *srcXEven, int *srcXOdd)
>  {
> -    int srcAdjust;
> +    uintptr_t srcAdjust;
>      int strideAdjust;
>  
>      /*
>       * bytes needed to align source
>       */
> -    srcAdjust = (((int) stip) & (FB_MASK >> 3));
> +    srcAdjust = (((uintptr_t) stip) & (FB_MASK >> 3));
>      /*
>       * FbStip units needed to align stride
>       */
> -- 
> 1.8.5.3


More information about the xorg-devel mailing list