Re: [PATCH i-g-t 2/7] Cast void * pointer used in arithmetic to uint32_t*

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jul 07, 2018 at 08:22:38PM -0300, Rodrigo Siqueira wrote:
> This commit fixes the GCC warning:
> 
> warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
>      memset(ptr + offsets[0], full_range ? 0x00 : 0x10,
>                 ^
> warning: pointer of type ‘void *’ used in arithmetic [-Wpointer-arith]
>      memset(ptr + offsets[1], 0x80,
> 
> This commit cast the ptr pointer, which is a void *, to uint32_t * in
> the pointer arithmetic operation.

This will change semantics, as according to GNU C standard[1], void
pointers have a size of 1 for all arithmetical purposes.

So you should be using uint8_t (or char) pointer instead.

[1]: http://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

> Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@xxxxxxxxx>
> ---
>  lib/igt_fb.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index ae71d967..ca905038 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -410,9 +410,11 @@ static int create_bo_for_fb(int fd, int width, int height,
>  
>  			switch (format->drm_id) {
>  			case DRM_FORMAT_NV12:
> -				memset(ptr + offsets[0], full_range ? 0x00 : 0x10,
> +				memset(((uint32_t *)ptr) + offsets[0],
> +				       full_range ? 0x00 : 0x10,
>  				       calculated_stride * height);
> -				memset(ptr + offsets[1], 0x80,
> +				memset(((uint32_t *)ptr) + offsets[1],
> +				       0x80,
>  				       calculated_stride * height/2);
>  				break;
>  			case DRM_FORMAT_YUYV:
> -- 
> 2.18.0
> 
_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux