[igt-dev] [PATCH i-g-t] tests/sw_sync: fix gcc warning

Petri Latvala petri.latvala at intel.com
Tue Oct 15 10:52:29 UTC 2019


On Sun, Oct 13, 2019 at 10:08:15PM +0300, Juha-Pekka Heikkila wrote:
> casting void pointer to int pointer causes gcc to be unhapy with comment:
> "warning: dereferencing type-punned pointer will break strict-aliasing 
> rules"

Make that "casting unsigned char pointer to int pointer".

If it had been void* it would have been fine.


Reviewed-by: Petri Latvala <petri.latvala at intel.com>



> 
> change:
> *((int *) CMSG_DATA(cmsg)) = timeline;
> to:
> memcpy(CMSG_DATA(cmsg), &timeline, sizeof(timeline));
> 
> so everyting is nicely defined for compiler.
> 
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
>  tests/sw_sync.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/sw_sync.c b/tests/sw_sync.c
> index 62d1d17..626b6d3 100644
> --- a/tests/sw_sync.c
> +++ b/tests/sw_sync.c
> @@ -228,7 +228,7 @@ static void test_sync_busy_fork_unixsocket(void)
>  		cmsg->cmsg_type = SCM_RIGHTS;
>  		cmsg->cmsg_len = CMSG_LEN(sizeof(timeline));
>  
> -		*((int *) CMSG_DATA(cmsg)) = timeline;
> +		memcpy(CMSG_DATA(cmsg), &timeline, sizeof(timeline));
>  		msg.msg_controllen = cmsg->cmsg_len;
>  
>  		igt_assert_f(sync_fence_wait(fence, 0) == -ETIME,
> -- 
> 2.7.4
> 
> _______________________________________________
> igt-dev mailing list
> igt-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev


More information about the igt-dev mailing list