From 62dd7e47e9eed118d012758c4a7297ffa9978868 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Tue, 4 May 2021 18:11:40 +0100 Subject: [PATCH] tests: Remove some compiler warnings Remove warnings like: In file included from /usr/include/glib-2.0/glib.h:86, from ../server/tests/test-glib-compat.h:21, from ../server/tests/test-channel.cpp:25: In function 'void send_ack_sync(int, uint32_t)', inlined from 'void channel_loop()' at ../server/tests/test-channel.cpp:250:18: ../server/sys-socket.h:28:43: error: 'ssize_t write(int, const void*, size_t)' reading 10 bytes from a region of size 2 [-Werror=stringop-overread] 28 | #define socket_write(sock, buf, len) write(sock, buf, len) /usr/include/glib-2.0/glib/gtestutils.h:50:61: note: in definition of macro 'g_assert_cmpint' 50 | gint64 __n1 = (n1), __n2 = (n2); \ | ^~ ../server/tests/test-channel.cpp:132:21: note: in expansion of macro 'socket_write' 132 | g_assert_cmpint(socket_write(socket, &msg.type, 10), ==, 10); | ^~~~~~~~~~~~ ../server/tests/test-channel.cpp: In function 'void channel_loop()': ../server/tests/test-channel.cpp:123:18: note: source object 'send_ack_sync(int, uint32_t)::::type' of size 2 123 | uint16_t type; | ^~~~ In file included from ../server/tests/test-channel.cpp:22: /usr/include/unistd.h:367:16: note: in a call to function 'ssize_t write(int, const void*, size_t)' declared with attribute 'access (read_only, 2, 3)' 367 | extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur | ^~~~~ cc1plus: all warnings being treated as errors Signed-off-by: Frediano Ziglio Acked-by: Marc-André Lureau --- server/tests/test-channel.cpp | 2 +- server/tests/test-smartcard.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/server/tests/test-channel.cpp b/server/tests/test-channel.cpp index 036f499..ffd0ec0 100644 --- a/server/tests/test-channel.cpp +++ b/server/tests/test-channel.cpp @@ -129,7 +129,7 @@ static void send_ack_sync(int socket, uint32_t generation) msg.len = GUINT32_TO_LE(sizeof(generation)); msg.generation = GUINT32_TO_LE(generation); - g_assert_cmpint(socket_write(socket, &msg.type, 10), ==, 10); + g_assert_cmpint(socket_write(socket, reinterpret_cast(&msg) + 2, 10), ==, 10); } static SpiceTimer *waked_up_timer; diff --git a/server/tests/test-smartcard.cpp b/server/tests/test-smartcard.cpp index 8c127e2..f76f602 100644 --- a/server/tests/test-smartcard.cpp +++ b/server/tests/test-smartcard.cpp @@ -108,7 +108,7 @@ static void send_ack_sync(int socket, uint32_t generation) msg.len = GUINT32_TO_LE(sizeof(generation)); msg.generation = GUINT32_TO_LE(generation); - g_assert_cmpint(socket_write(socket, &msg.type, 10), ==, 10); + g_assert_cmpint(socket_write(socket, reinterpret_cast(&msg) + 2, 10), ==, 10); } static void send_data(int socket, uint32_t type, uint32_t reader_id) @@ -128,7 +128,8 @@ static void send_data(int socket, uint32_t type, uint32_t reader_id) msg.vheader.length = GUINT32_TO_LE(6); strcpy(msg.data, "hello"); - g_assert_cmpint(socket_write(socket, &msg.type, sizeof(msg)-4), ==, sizeof(msg)-4); + g_assert_cmpint(socket_write(socket, reinterpret_cast(&msg) + 2, + sizeof(msg) - 4), ==, sizeof(msg) - 4); } static void check_data(VmcEmu *vmc_emu) -- libgit2 1.3.0