nwrap: Fix the handle loops for older gcc versions.
authorAndreas Schneider <asn@samba.org>
Wed, 1 Oct 2014 15:15:35 +0000 (17:15 +0200)
committerMichael Adam <obnox@samba.org>
Mon, 11 Jan 2016 11:25:26 +0000 (12:25 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
lib/nss_wrapper/nss_wrapper.c

index a41de9e9fbb3af3d5e7296c2b0d5b182272b4bdb..28c23d81117e81c2f9d41bac6a1b0b1b386db1af 100644 (file)
@@ -575,11 +575,14 @@ static void *nwrap_load_lib_handle(enum nwrap_lib lib)
 #ifdef HAVE_LIBNSL
                handle = nwrap_main_global->libc->nsl_handle;
                if (handle == NULL) {
-                       for (handle = NULL, i = 10; handle == NULL && i >= 0; i--) {
+                       for (i = 10; i >= 0; i--) {
                                char soname[256] = {0};
 
                                snprintf(soname, sizeof(soname), "libnsl.so.%d", i);
                                handle = dlopen(soname, flags);
+                               if (handle != NULL) {
+                                       break;
+                               }
                        }
 
                        nwrap_main_global->libc->nsl_handle = handle;
@@ -591,11 +594,14 @@ static void *nwrap_load_lib_handle(enum nwrap_lib lib)
 #ifdef HAVE_LIBSOCKET
                handle = nwrap_main_global->libc->sock_handle;
                if (handle == NULL) {
-                       for (handle = NULL, i = 10; handle == NULL && i >= 0; i--) {
+                       for (i = 10; i >= 0; i--) {
                                char soname[256] = {0};
 
                                snprintf(soname, sizeof(soname), "libsocket.so.%d", i);
                                handle = dlopen(soname, flags);
+                               if (handle != NULL) {
+                                       break;
+                               }
                        }
 
                        nwrap_main_global->libc->sock_handle = handle;
@@ -606,11 +612,14 @@ static void *nwrap_load_lib_handle(enum nwrap_lib lib)
        case NWRAP_LIBC:
                handle = nwrap_main_global->libc->handle;
                if (handle == NULL) {
-                       for (handle = NULL, i = 10; handle == NULL && i >= 0; i--) {
+                       for (i = 10; i >= 0; i--) {
                                char soname[256] = {0};
 
                                snprintf(soname, sizeof(soname), "libc.so.%d", i);
                                handle = dlopen(soname, flags);
+                               if (handle != NULL) {
+                                       break;
+                               }
                        }
 
                        nwrap_main_global->libc->handle = handle;