From 1fe101747cb8dcef8c9444bdec4da77930ceaf36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 5 Feb 2018 10:55:24 +0100 Subject: [PATCH 1/2] basic/glob-util: add closedir wrapper to silence gcc ../src/test/test-glob-util.c: In function 'test_glob_no_dot': ../src/test/test-glob-util.c:61:32: warning: cast between incompatible function types from 'int (*)(DIR *)' {aka 'int (*)(struct __dirstream *)'} to 'void (*)(void *)' [-Wcast-function-type] .gl_closedir = (void (*)(void *)) closedir, ^ --- src/basic/glob-util.c | 6 +++++- src/test/test-glob-util.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/basic/glob-util.c b/src/basic/glob-util.c index 6e80a1e23b5..a6ba9ef1634 100644 --- a/src/basic/glob-util.c +++ b/src/basic/glob-util.c @@ -29,6 +29,10 @@ #include "path-util.h" #include "strv.h" +static void _closedir(void* v) { + (void) closedir(v); +} + int safe_glob(const char *path, int flags, glob_t *pglob) { int k; @@ -36,7 +40,7 @@ int safe_glob(const char *path, int flags, glob_t *pglob) { assert(!(flags & GLOB_ALTDIRFUNC)); if (!pglob->gl_closedir) - pglob->gl_closedir = (void (*)(void *)) closedir; + pglob->gl_closedir = _closedir; if (!pglob->gl_readdir) pglob->gl_readdir = (struct dirent *(*)(void *)) readdir_no_dot; if (!pglob->gl_opendir) diff --git a/src/test/test-glob-util.c b/src/test/test-glob-util.c index bd2f8fcfde6..ab40a2a4bee 100644 --- a/src/test/test-glob-util.c +++ b/src/test/test-glob-util.c @@ -49,12 +49,16 @@ static void test_glob_exists(void) { assert_se(r == 0); } +static void _closedir(void* v) { + (void) closedir(v); +} + static void test_glob_no_dot(void) { char template[] = "/tmp/test-glob-util.XXXXXXX"; const char *fn; _cleanup_globfree_ glob_t g = { - .gl_closedir = (void (*)(void *)) closedir, + .gl_closedir = _closedir, .gl_readdir = (struct dirent *(*)(void *)) readdir_no_dot, .gl_opendir = (void *(*)(const char *)) opendir, .gl_lstat = lstat, From 3c3d384ae93700ef08545b078c37065fdb98eee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 5 Feb 2018 11:07:40 +0100 Subject: [PATCH 2/2] nss-systemd: add work-around to silence gcc warning In file included from ../src/basic/fs-util.h:32, from ../src/nss-systemd/nss-systemd.c:28: ../src/nss-systemd/nss-systemd.c: In function '_nss_systemd_getgrnam_r': ../src/nss-systemd/nss-systemd.c:416:32: warning: argument to 'sizeof' in 'memset' call is the same pointer type 'char *' as the destination; expected 'char' or an explicit length [-Wsizeof-pointer-memaccess] memzero(buffer, sizeof(char*)); ^~~~ ../src/basic/util.h:118:39: note: in definition of macro 'memzero' #define memzero(x,l) (memset((x), 0, (l))) ^ gcc is trying to be helpful, and it's not far from being right. It _looks_ like sizeof(char*) is an error, but in this case we're really leaving a space empty for a pointer, and our calculation is correct. Since this is a short file, let's just use simplest option and turn off the warning above the two functions that trigger it. --- src/nss-systemd/nss-systemd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nss-systemd/nss-systemd.c b/src/nss-systemd/nss-systemd.c index f75405d2e55..c502b5f5fd0 100644 --- a/src/nss-systemd/nss-systemd.c +++ b/src/nss-systemd/nss-systemd.c @@ -328,6 +328,8 @@ fail: return NSS_STATUS_UNAVAIL; } +#pragma GCC diagnostic ignored "-Wsizeof-pointer-memaccess" + enum nss_status _nss_systemd_getgrnam_r( const char *name, struct group *gr,