[PATCH 4/5] Update dlerror usage
Chris Johns
chrisj at rtems.org
Thu Feb 8 03:47:20 UTC 2018
From: Patrick Gauvin <gauvin at hcs.ufl.edu>
Handles possible NULL return value
Updates #3298
---
cpukit/libdl/dlfcn-shell.c | 8 ++++++--
testsuites/libtests/dl01/dl-load.c | 7 +++++--
testsuites/libtests/dl02/dl-load.c | 11 ++++++++---
3 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/cpukit/libdl/dlfcn-shell.c b/cpukit/libdl/dlfcn-shell.c
index 3746711ef1..12c737abb6 100644
--- a/cpukit/libdl/dlfcn-shell.c
+++ b/cpukit/libdl/dlfcn-shell.c
@@ -38,7 +38,8 @@ convert_ascii_to_voidp (const char* arg)
int
shell_dlopen (int argc, char* argv[])
{
- int arg;
+ int arg;
+ char *err;
for (arg = 1; arg < argc; arg++)
{
void* handle = dlopen (argv[arg], RTLD_NOW | RTLD_GLOBAL);
@@ -53,7 +54,10 @@ shell_dlopen (int argc, char* argv[])
printf ("handle: %p %s\n", handle, message);
}
else
- printf ("error: %s\n", dlerror ());
+ {
+ err = dlerror ();
+ printf ("error: %s\n", err ? err : "");
+ }
}
return 0;
}
diff --git a/testsuites/libtests/dl01/dl-load.c b/testsuites/libtests/dl01/dl-load.c
index e8f84bd5b5..7441808b24 100644
--- a/testsuites/libtests/dl01/dl-load.c
+++ b/testsuites/libtests/dl01/dl-load.c
@@ -27,13 +27,15 @@ int dl_load_test(void)
int call_ret;
int unresolved;
char* message = "loaded";
+ char* err;
printf("load: /dl-o1.o\n");
handle = dlopen ("/dl-o1.o", RTLD_NOW | RTLD_GLOBAL);
if (!handle)
{
- printf("dlopen failed: %s\n", dlerror());
+ err = dlerror ();
+ printf ("dlopen failed: %s\n", err ? err : "");
return 1;
}
@@ -67,7 +69,8 @@ int dl_load_test(void)
if (dlclose (handle) < 0)
{
- printf("dlclose failed: %s\n", dlerror());
+ err = dlerror ();
+ printf ("dlclose failed: %s\n", err ? err : "");
return 1;
}
diff --git a/testsuites/libtests/dl02/dl-load.c b/testsuites/libtests/dl02/dl-load.c
index 5bb40dccba..5e74e0e425 100644
--- a/testsuites/libtests/dl02/dl-load.c
+++ b/testsuites/libtests/dl02/dl-load.c
@@ -21,13 +21,15 @@ static void* dl_load_obj(const char* name)
void* handle;
int unresolved;
char* message = "loaded";
+ char* err;
printf("load: %s\n", name);
handle = dlopen (name, RTLD_NOW | RTLD_GLOBAL);
if (!handle)
{
- printf("dlopen failed: %s\n", dlerror());
+ err = dlerror ();
+ printf ("dlopen failed: %s\n", err ? err : "");
return NULL;
}
@@ -48,6 +50,7 @@ int dl_load_test(void)
call_t call;
int call_ret;
int ret;
+ char* err;
o1 = dl_load_obj("/dl-o1.o");
if (!o1)
@@ -83,7 +86,8 @@ int dl_load_test(void)
if (dlclose (o1) < 0)
{
- printf("dlclose o1 failed: %s\n", dlerror());
+ err = dlerror ();
+ printf ("dlclose o1 failed: %s\n", err ? err : "");
ret = 1;
}
@@ -91,7 +95,8 @@ int dl_load_test(void)
if (dlclose (o2) < 0)
{
- printf("dlclose o1 failed: %s\n", dlerror());
+ err = dlerror ();
+ printf ("dlclose o2 failed: %s\n", err ? err : "");
ret = 1;
}
--
2.14.1
More information about the devel
mailing list