diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-05-24 21:03:56 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-05-24 21:03:56 +0200 |
commit | 58912f68c2489bcee787599837447e0d64dfd61a (patch) | |
tree | dda50aadde35fe152da1a8d50769987ace0f1496 /backend/dll.c | |
parent | cfd27ef2ad8b005fd47ab41ef29b71d9e3d48201 (diff) |
New upstream version 1.0.27upstream/1.0.27
Diffstat (limited to 'backend/dll.c')
-rw-r--r-- | backend/dll.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/backend/dll.c b/backend/dll.c index 5264f11..5eaa046 100644 --- a/backend/dll.c +++ b/backend/dll.c @@ -69,6 +69,26 @@ #if defined(HAVE_DLOPEN) && defined(HAVE_DLFCN_H) # include <dlfcn.h> + /* This works around a pedantic GCC compiler warning. The ISO C + standard says that the behaviour of converting an object pointer + like the void * returned by dlsym() to a function pointer like + void *(*)() is implementation defined. POSIX though guarantees + that this works fine. + + Workaround based on http://stackoverflow.com/a/36385690. Turns + off pedantic warnings for the duration of the definition only. + */ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +typedef void *(*func_ptr)(void); + +func_ptr +posix_dlsym (void *handle, const char *func) +{ + return dlsym (handle, func); +} +# pragma GCC diagnostic pop + /* 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 @@ -430,15 +450,17 @@ load (struct backend *be) if (path) { - src_len = strlen (path) + strlen (LIBDIR) + 1 + 1; + src_len = strlen (path) + strlen (DIR_SEP) + strlen(LIBDIR) + 1; src = malloc (src_len); if (!src) { DBG (1, "load: malloc failed: %s\n", strerror (errno)); return SANE_STATUS_NO_MEM; } + if (orig_src) + free (orig_src); orig_src = src; - snprintf (src, src_len, "%s:%s", path, LIBDIR); + snprintf (src, src_len, "%s%s%s", path, DIR_SEP, LIBDIR); } else { @@ -534,7 +556,7 @@ load (struct backend *be) /* First try looking up the symbol without a leading underscore. */ #ifdef HAVE_DLOPEN - op = (void *(*)(void)) dlsym (be->handle, funcname + 1); + op = posix_dlsym (be->handle, funcname + 1); #elif defined(HAVE_SHL_LOAD) shl_findsym ((shl_t *) & (be->handle), funcname + 1, TYPE_UNDEFINED, &op); @@ -559,7 +581,7 @@ load (struct backend *be) { /* Try again, with an underscore prepended. */ #ifdef HAVE_DLOPEN - op = (void *(*)(void)) dlsym (be->handle, funcname); + op = posix_dlsym (be->handle, funcname); #elif defined(HAVE_SHL_LOAD) shl_findsym (be->handle, funcname, TYPE_UNDEFINED, &op); #elif defined(HAVE_NSLINKMODULE) |