[rtems commit] Update dlerror usage

Chris Johns chrisj at rtems.org
Thu Feb 8 22:32:33 UTC 2018


Module:    rtems
Branch:    4.11
Commit:    5812a26eeb8928f34eadc5c5dfca74563a824cd0
Changeset: http://git.rtems.org/rtems/commit/?id=5812a26eeb8928f34eadc5c5dfca74563a824cd0

Author:    Patrick Gauvin <gauvin at hcs.ufl.edu>
Date:      Sun Jun 26 13:06:07 2016 -0400

Update dlerror usage

Handles possible NULL return value

Updates #2747

---

 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 3746711..12c737a 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 e8f84bd..7441808 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 5bb40dc..5e74e0e 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;
   }
 



More information about the vc mailing list