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

Juha-Pekka Heikkila juhapekka.heikkila at gmail.com
Sun Oct 13 19:08:15 UTC 2019


casting void pointer to int pointer causes gcc to be unhapy with comment:
"warning: dereferencing type-punned pointer will break strict-aliasing 
rules"

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



More information about the igt-dev mailing list