From bf3c4219fe01c50edbc19361592b6846d132e306 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 28 May 2020 20:09:43 +1200 Subject: [PATCH] Make rk_SOCK_INIT an inline function and check the result to avoid warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Similar to f6e0d19cc036bc3601c2b8a8d9c064adbace9737 but fixed in the header by making it a proper static inline function (as some callers treats it as one, so do it for all now for consistency). Seen on Ubuntu 18.04 with giving: In file included from getaddrinfo-test.c:36:0: getaddrinfo-test.c: In function ‘main’: roken.h:110:24: error: statement with no effect [-Werror=unused-value] #define rk_SOCK_INIT() 0 ^ getaddrinfo-test.c:132:5: note: in expansion of macro ‘rk_SOCK_INIT’ rk_SOCK_INIT(); ^~~~~~~~~~~~ Signed-off-by: Andrew Bartlett --- lib/roken/getaddrinfo-test.c | 3 ++- lib/roken/roken.h.in | 5 ++++- lib/roken/test-mini_inetd.c | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/roken/getaddrinfo-test.c b/lib/roken/getaddrinfo-test.c index d5aaeb2e0..9d33b2ec6 100644 --- a/lib/roken/getaddrinfo-test.c +++ b/lib/roken/getaddrinfo-test.c @@ -129,7 +129,8 @@ main(int argc, char **argv) return 0; } - rk_SOCK_INIT(); + if (rk_SOCK_INIT()) + errx(1, "Couldn't initialize sockets. Err=%d\n", rk_SOCK_ERRNO); argc -= optidx; argv += optidx; diff --git a/lib/roken/roken.h.in b/lib/roken/roken.h.in index 9cd1c0fc6..e1aa6b7b6 100644 --- a/lib/roken/roken.h.in +++ b/lib/roken/roken.h.in @@ -132,7 +132,10 @@ typedef int rk_socket_t; #define rk_SOCK_ERRNO errno #define rk_INVALID_SOCKET (-1) -#define rk_SOCK_INIT() 0 +static inline ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_SOCK_INIT(void) { + return 0; +} + #define rk_SOCK_EXIT() do { } while(0) #endif /* WinSock */ diff --git a/lib/roken/test-mini_inetd.c b/lib/roken/test-mini_inetd.c index 5afdf74ed..b11447060 100644 --- a/lib/roken/test-mini_inetd.c +++ b/lib/roken/test-mini_inetd.c @@ -253,7 +253,8 @@ do_client(void) { int rv = 0; - rk_SOCK_INIT(); + if (rk_SOCK_INIT()) + errx(1, "Couldn't initialize sockets. Err=%d\n", rk_SOCK_ERRNO); prog = "Client"; is_client = 1; @@ -272,7 +273,8 @@ do_server(void) { int rv = 0; - rk_SOCK_INIT(); + if (rk_SOCK_INIT()) + errx(1, "Couldn't initialize sockets. Err=%d\n", rk_SOCK_ERRNO); prog = "Server";