From a993e6438eff1e5b71f1dcc97df478ca954aae9f Mon Sep 17 00:00:00 2001 From: Olaf Meeuwissen Date: Sun, 22 Dec 2019 16:05:51 +0900 Subject: [PATCH 1/3] dll: Fix [-Wformat-truncation=] compiler warning Per POSIX, `readdir` returns filenames that are at most `NAME_MAX` long. --- backend/dll.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/dll.c b/backend/dll.c index 926a08064..c88818c4f 100644 --- a/backend/dll.c +++ b/backend/dll.c @@ -799,7 +799,8 @@ read_dlld (void) DIR *dlld; struct dirent *dllconf; struct stat st; - char conffile[PATH_MAX], dlldir[PATH_MAX]; + char dlldir[PATH_MAX]; + char conffile[PATH_MAX + strlen("/") + NAME_MAX]; size_t len, plen; const char *dir_list; char *copy, *next, *dir; @@ -851,7 +852,7 @@ read_dlld (void) || (dllconf->d_name[len-1] == '#')) continue; - snprintf (conffile, PATH_MAX, "%s/%s", dlldir, dllconf->d_name); + snprintf (conffile, sizeof(conffile), "%s/%s", dlldir, dllconf->d_name); DBG (5, "sane_init/read_dlld: considering %s\n", conffile); From e7f6c6e864200fc51a05c8eb5963a78b3251adbd Mon Sep 17 00:00:00 2001 From: Olaf Meeuwissen Date: Sun, 22 Dec 2019 17:58:39 +0900 Subject: [PATCH 2/3] dll: Ignore [-Wcast-function-type] compiler warnings --- backend/dll.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backend/dll.c b/backend/dll.c index c88818c4f..39531bd43 100644 --- a/backend/dll.c +++ b/backend/dll.c @@ -89,6 +89,19 @@ posix_dlsym (void *handle, const char *func) } # pragma GCC diagnostic pop + /* Similar to the above, GCC also warns about conversion between + pointers to functions. The ISO C standard says that invoking a + converted pointer to a function whose type is not compatible with + the pointed-to type, the behavior is undefined. Although GCC is + correct to warn about this, the dll backend has been using these + conversions without issues for a very long time already. + + Rather than push/pop around every use, which would get very ugly + real fast, ignore this particular warning for the remainder of + the file. + */ +# pragma GCC diagnostic ignored "-Wcast-function-type" + /* Older versions of dlopen() don't define RTLD_NOW and RTLD_LAZY. They all seem to use a mode of 1 to indicate RTLD_NOW and some do not support RTLD_LAZY at all. Hence, unless defined, we define From fd407cc58bce4162a8329fb4ec587837f50c1fd0 Mon Sep 17 00:00:00 2001 From: Olaf Meeuwissen Date: Sun, 22 Dec 2019 18:34:45 +0900 Subject: [PATCH 3/3] dll: Make previous change backwardly compatible Older GCC do not know the cast-function-pragma and flag that as a warning. That results in an error on our Debian 9 build. --- backend/dll.c | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/dll.c b/backend/dll.c index 39531bd43..73ffde41c 100644 --- a/backend/dll.c +++ b/backend/dll.c @@ -100,6 +100,7 @@ posix_dlsym (void *handle, const char *func) real fast, ignore this particular warning for the remainder of the file. */ +# pragma GCC diagnostic ignored "-Wpragmas" /* backward compatibility */ # pragma GCC diagnostic ignored "-Wcast-function-type" /* Older versions of dlopen() don't define RTLD_NOW and RTLD_LAZY.