From 5f1bf3106bbcf8e66a056897b9ca2f604fe4ac6c Mon Sep 17 00:00:00 2001
From: William Brown <firstyear@redhat.com>
Date: Thu, 10 Aug 2017 12:10:24 +1000
Subject: [PATCH] Ticket 49275 - fix compiler warns for gcc 7

Bug Description:  GCC 7 enables many more stricter warnings about
code quality.

Fix Description:  Fix another set of shadow vars, case fall
throughs and unused functions.

https://pagure.io/389-ds-base/issue/49275

Author: wibrown

Review by: ???
---
 ldap/servers/plugins/chainingdb/cb_acl.c |  9 ++-----
 ldap/servers/plugins/syntaxes/string.c   |  8 +++----
 ldap/servers/slapd/back-ldbm/dblayer.c   | 21 +++++++++++------
 ldap/servers/slapd/back-ldbm/sort.c      |  1 -
 ldap/servers/slapd/dn.c                  | 10 ++++----
 ldap/servers/slapd/ldaputil.c            | 38 ++++++++++++++++--------------
 ldap/servers/slapd/result.c              | 12 +++++-----
 ldap/servers/slapd/ssl.c                 |  2 ++
 ldap/servers/slapd/tools/ldclt/ldclt.h   |  2 +-
 ldap/servers/slapd/utf8.c                | 40 ++++++++++++++++++++++++--------
 src/libsds/test/test_sds_bpt.c           |  6 +++--
 11 files changed, 89 insertions(+), 60 deletions(-)

diff --git a/ldap/servers/plugins/chainingdb/cb_acl.c b/ldap/servers/plugins/chainingdb/cb_acl.c
index 2714b46..0378231 100644
--- a/ldap/servers/plugins/chainingdb/cb_acl.c
+++ b/ldap/servers/plugins/chainingdb/cb_acl.c
@@ -32,13 +32,8 @@ cb_set_acl_policy(Slapi_PBlock *pb)
            or if the associated backend is disabled */
     noacl = !(cb->local_acl) || cb->associated_be_is_disabled;
 
-    /* These branches are identical. Can we remove the if condition? */
-    if (noacl) {
-        slapi_pblock_set(pb, SLAPI_PLUGIN_DB_NO_ACL, &noacl);
-    } else {
-        /* Be very conservative about acl evaluation */
-        slapi_pblock_set(pb, SLAPI_PLUGIN_DB_NO_ACL, &noacl);
-    }
+    /* Be very conservative about acl evaluation */
+    slapi_pblock_set(pb, SLAPI_PLUGIN_DB_NO_ACL, &noacl);
 }
 
 int
diff --git a/ldap/servers/plugins/syntaxes/string.c b/ldap/servers/plugins/syntaxes/string.c
index 364276b..f50dc13 100644
--- a/ldap/servers/plugins/syntaxes/string.c
+++ b/ldap/servers/plugins/syntaxes/string.c
@@ -26,7 +26,7 @@
 static int string_filter_approx(struct berval *bvfilter,
                                 Slapi_Value **bvals,
                                 Slapi_Value **retVal);
-static void substring_comp_keys(Slapi_Value ***ivals, int *nsubs, char *str, int lenstr, int prepost, int syntax, char *comp_buf, int *substrlens);
+static void substring_comp_keys(Slapi_Value ***ivals, int *nsubs, char *str, int lenstring, int prepost, int syntax, char *comp_buf, int *substrlens);
 
 int
 string_filter_ava(struct berval *bvfilter, Slapi_Value **bvals, int syntax, int ftype, Slapi_Value **retVal)
@@ -901,7 +901,7 @@ substring_comp_keys(
     Slapi_Value ***ivals,
     int *nsubs,
     char *str,
-    int lenstr,
+    int lenstring,
     int prepost,
     int syntax __attribute__((unused)),
     char *comp_buf,
@@ -929,7 +929,7 @@ substring_comp_keys(
     }
 
     substrlen = substrlens[INDEX_SUBSTRMIDDLE];
-    for (p = str; p < (str + lenstr - substrlen + 1); p++) {
+    for (p = str; p < (str + lenstring - substrlen + 1); p++) {
         for (i = 0; i < substrlen; i++) {
             comp_buf[i] = p[i];
         }
@@ -940,7 +940,7 @@ substring_comp_keys(
 
     if (prepost == '$') {
         substrlen = substrlens[INDEX_SUBSTREND];
-        p = str + lenstr - substrlen + 1;
+        p = str + lenstring - substrlen + 1;
         for (i = 0; i < substrlen - 1; i++) {
             comp_buf[i] = p[i];
         }
diff --git a/ldap/servers/slapd/back-ldbm/dblayer.c b/ldap/servers/slapd/back-ldbm/dblayer.c
index 620af6a..5eb2b9e 100644
--- a/ldap/servers/slapd/back-ldbm/dblayer.c
+++ b/ldap/servers/slapd/back-ldbm/dblayer.c
@@ -4645,42 +4645,49 @@ db_strtoul(const char *str, int *err)
     for (p = (char *)str; p && *p && (*p == ' ' || *p == '\t'); p++)
         ;
     if ('-' == *p) {
-        if (err)
+        if (err) {
             *err = ERANGE;
+        }
         return val;
     }
     val = strtoul(str, &p, 10);
     if (errno != 0) {
-        if (err)
+        if (err) {
             *err = errno;
+        }
         return val;
     }
 
     switch (*p) {
     case 'g':
     case 'G':
-        multiplier *= 1024;
+        multiplier *= 1024 * 1024 * 1024;
+        break;
     case 'm':
     case 'M':
-        multiplier *= 1024;
+        multiplier *= 1024 * 1024;
+        break;
     case 'k':
     case 'K':
         multiplier *= 1024;
         p++;
-        if (*p == 'b' || *p == 'B')
+        if (*p == 'b' || *p == 'B') {
             p++;
+        }
         if (err) {
             /* extra chars? */
             *err = (*p != '\0') ? EINVAL : 0;
         }
         break;
     case '\0':
-        if (err)
+        if (err) {
             *err = 0;
+        }
         break;
     default:
-        if (err)
+        if (err) {
             *err = EINVAL;
+        }
         return val;
     }
 
diff --git a/ldap/servers/slapd/back-ldbm/sort.c b/ldap/servers/slapd/back-ldbm/sort.c
index 45b1b90..5b84d87 100644
--- a/ldap/servers/slapd/back-ldbm/sort.c
+++ b/ldap/servers/slapd/back-ldbm/sort.c
@@ -163,7 +163,6 @@ sort_candidates(backend *be, int lookthrough_limit, struct timespec *expire_time
     /* Iterate over the sort types */
     for (this_s = s; this_s; this_s = this_s->next) {
         if (NULL == this_s->matchrule) {
-            int return_value = 0;
             return_value = attr_get_value_cmp_fn(&this_s->sattr, &(this_s->compare_fn));
             if (return_value != 0) {
                 slapi_log_err(SLAPI_LOG_TRACE, "sort_candidates",
diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c
index 915b230..afca372 100644
--- a/ldap/servers/slapd/dn.c
+++ b/ldap/servers/slapd/dn.c
@@ -733,6 +733,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
                 subtypestart = d; /* prepare for '+' in the nested DN, if any */
             }
             subrdn_av_count = 0;
+            /* FALLTHRU */
         case INVALUE: /* in value; cn=ABC */
                       /*               ^  */
             if (ISESCAPE(*s)) {
@@ -958,6 +959,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len)
                 subtypestart = d; /* prepare for '+' in the quoted value, if any */
             }
             subrdn_av_count = 0;
+            /* FALLTHRU */
         case INQUOTEDVALUE:
             if (ISQUOTE(*s)) {
                 if (ISESCAPE(*(d - 1))) {            /* the quote is escaped */
@@ -2433,10 +2435,10 @@ slapi_sdn_get_parent(const Slapi_DN *sdn, Slapi_DN *sdn_parent)
 void
 slapi_sdn_get_backend_parent_ext(const Slapi_DN *sdn,
                                  Slapi_DN *sdn_parent,
-                                 const Slapi_Backend *backend,
+                                 const Slapi_Backend *be,
                                  int is_tombstone)
 {
-    if (slapi_sdn_isempty(sdn) || slapi_be_issuffix(backend, sdn)) {
+    if (slapi_sdn_isempty(sdn) || slapi_be_issuffix(be, sdn)) {
         slapi_sdn_done(sdn_parent);
     } else {
         slapi_sdn_get_parent_ext(sdn, sdn_parent, is_tombstone);
@@ -2444,9 +2446,9 @@ slapi_sdn_get_backend_parent_ext(const Slapi_DN *sdn,
 }
 
 void
-slapi_sdn_get_backend_parent(const Slapi_DN *sdn, Slapi_DN *sdn_parent, const Slapi_Backend *backend)
+slapi_sdn_get_backend_parent(const Slapi_DN *sdn, Slapi_DN *sdn_parent, const Slapi_Backend *be)
 {
-    slapi_sdn_get_backend_parent_ext(sdn, sdn_parent, backend, 0);
+    slapi_sdn_get_backend_parent_ext(sdn, sdn_parent, be, 0);
 }
 
 void
diff --git a/ldap/servers/slapd/ldaputil.c b/ldap/servers/slapd/ldaputil.c
index 6592103..fa9d276 100644
--- a/ldap/servers/slapd/ldaputil.c
+++ b/ldap/servers/slapd/ldaputil.c
@@ -1131,11 +1131,11 @@ slapi_ldap_bind(
                 }
             }
             if (0 == myerrno) {
-                struct addrinfo *result = NULL;
-                gaierr = getaddrinfo(hostname, NULL, NULL, &result);
+                struct addrinfo *a_result = NULL;
+                gaierr = getaddrinfo(hostname, NULL, NULL, &a_result);
                 myerrno = errno;
-                if (result) {
-                    freeaddrinfo(result);
+                if (a_result) {
+                    freeaddrinfo(a_result);
                 }
             }
 
@@ -2301,14 +2301,17 @@ mozldap_ldap_explode(const char *dn, const int notypes, const int nametype)
                 plen = LDAP_UTF8LEN(p);
             break;
         case '"':
-            if (state == INQUOTE)
+            if (state == INQUOTE) {
                 state = OUTQUOTE;
-            else
+            } else {
                 state = INQUOTE;
+            }
             break;
         case '+':
-            if (nametype != LDAP_RDN)
+            if (nametype != LDAP_RDN) {
                 break;
+            }
+            /* FALLTHRU */
         case ';':
         case ',':
         case '\0':
@@ -2334,8 +2337,9 @@ mozldap_ldap_explode(const char *dn, const int notypes, const int nametype)
                 goteq = 0;
                 ++count;
                 if (rdns == NULL) {
-                    if ((rdns = (char **)slapi_ch_malloc(8 * sizeof(char *))) == NULL)
+                    if ((rdns = (char **)slapi_ch_malloc(8 * sizeof(char *))) == NULL) {
                         return (NULL);
+                    }
                 } else if (count >= 8) {
                     if ((rdns = (char **)slapi_ch_realloc(
                              (char *)rdns, (count + 1) *
@@ -2345,8 +2349,7 @@ mozldap_ldap_explode(const char *dn, const int notypes, const int nametype)
                 rdns[count] = NULL;
                 endquote = 0;
                 if (notypes) {
-                    for (q = rdnstart;
-                         q < p && *q != '='; ++q) {
+                    for (q = rdnstart; q < p && *q != '='; ++q) {
                         ;
                     }
                     if (q < p) { /* *q == '=' */
@@ -2364,14 +2367,11 @@ mozldap_ldap_explode(const char *dn, const int notypes, const int nametype)
                 }
 
                 len = p - rdnstart;
-                if ((rdns[count - 1] = (char *)slapi_ch_calloc(
-                         1, len + 1)) != NULL) {
-                    memcpy(rdns[count - 1], rdnstart,
-                           len);
+                if ((rdns[count - 1] = (char *)slapi_ch_calloc(1, len + 1)) != NULL) {
+                    memcpy(rdns[count - 1], rdnstart, len);
                     if (!endquote) {
                         /* trim trailing spaces */
-                        while (len > 0 &&
-                               (rdns[count - 1][len - 1] == ' ')) {
+                        while (len > 0 && (rdns[count - 1][len - 1] == ' ')) {
                             --len;
                         }
                     }
@@ -2383,12 +2383,14 @@ mozldap_ldap_explode(const char *dn, const int notypes, const int nametype)
                  *  it should be.  If we don't, then we will
                  *  never get past an "end quote."
                  */
-                if (endquote == 1)
+                if (endquote == 1) {
                     p++;
+                }
 
                 rdnstart = *p ? p + 1 : p;
-                while (ldap_utf8isspace(rdnstart))
+                while (ldap_utf8isspace(rdnstart)) {
                     ++rdnstart;
+                }
             }
             break;
         case '=':
diff --git a/ldap/servers/slapd/result.c b/ldap/servers/slapd/result.c
index a361886..2302ae9 100644
--- a/ldap/servers/slapd/result.c
+++ b/ldap/servers/slapd/result.c
@@ -1208,12 +1208,12 @@ send_all_attrs(Slapi_Entry *e, char **attrs, Slapi_Operation *op, Slapi_PBlock *
             int item_count = 0;
             int iter = 0;
             Slapi_DN *namespace_dn;
-            Slapi_Backend *backend = 0;
+            Slapi_Backend *be = 0;
             vattr_context *ctx;
 
             /* get the namespace dn */
-            slapi_pblock_get(pb, SLAPI_BACKEND, (void *)&backend);
-            namespace_dn = (Slapi_DN *)slapi_be_getsuffix(backend, 0);
+            slapi_pblock_get(pb, SLAPI_BACKEND, (void *)&be);
+            namespace_dn = (Slapi_DN *)slapi_be_getsuffix(be, 0);
 
             /* Get the attribute value from the vattr service */
             /* ctx will be freed by attr_context_ungrok() */
@@ -1345,7 +1345,7 @@ send_specific_attrs(Slapi_Entry *e, char **attrs, Slapi_Operation *op, Slapi_PBl
         int item_count = 0;
         int iter = 0;
         Slapi_DN *namespace_dn;
-        Slapi_Backend *backend = 0;
+        Slapi_Backend *be = 0;
 
         /*
          * Here we call the computed attribute code to see whether
@@ -1366,8 +1366,8 @@ send_specific_attrs(Slapi_Entry *e, char **attrs, Slapi_Operation *op, Slapi_PBl
         }
 
         /* get the namespace dn */
-        slapi_pblock_get(pb, SLAPI_BACKEND, (void *)&backend);
-        namespace_dn = (Slapi_DN *)slapi_be_getsuffix(backend, 0);
+        slapi_pblock_get(pb, SLAPI_BACKEND, (void *)&be);
+        namespace_dn = (Slapi_DN *)slapi_be_getsuffix(be, 0);
 
         /* Get the attribute value from the vattr service */
         /* This call handles subtype, as well.
diff --git a/ldap/servers/slapd/ssl.c b/ldap/servers/slapd/ssl.c
index 11d207d..941d32c 100644
--- a/ldap/servers/slapd/ssl.c
+++ b/ldap/servers/slapd/ssl.c
@@ -2248,6 +2248,7 @@ slapd_ssl_init2(PRFileDesc **fd, int startTLS)
                               err, prerr, slapd_pr_strerror(prerr));
             }
 #endif
+            break;
         /* Give the client a clear opportunity to send her certificate: */
         case SLAPD_SSLCLIENTAUTH_REQUIRED:
             if ((err = SSL_OptionSet(pr_sock, SSL_REQUEST_CERTIFICATE, PR_TRUE)) < 0) {
@@ -2256,6 +2257,7 @@ slapd_ssl_init2(PRFileDesc **fd, int startTLS)
                               "SSL_OptionSet(SSL_REQUEST_CERTIFICATE,PR_TRUE) %d " SLAPI_COMPONENT_NAME_NSPR " error %d (%s)\n",
                               err, prerr, slapd_pr_strerror(prerr));
             }
+            break;
         default:
             break;
         }
diff --git a/ldap/servers/slapd/tools/ldclt/ldclt.h b/ldap/servers/slapd/tools/ldclt/ldclt.h
index bea17cb..1cfae35 100644
--- a/ldap/servers/slapd/tools/ldclt/ldclt.h
+++ b/ldap/servers/slapd/tools/ldclt/ldclt.h
@@ -196,7 +196,7 @@ dd/mm/yy | Author    | Comments
 #define NEGATIVE_MAX_ERROR_NB (LDAP_X_CONNECTING - 1) /* Mininum ldap err number */
 #endif
 #define MAX_IGN_ERRORS 20                            /* Max errors ignored */
-#define MAX_FILTER 512                               /* Max filters length */
+#define MAX_FILTER 4096                               /* Max filters length */
 #define MAX_THREADS 1000 /* Max number of threads */ /*JLS 21-11-00*/
 #define MAX_SLAVES 20                                /* Max number of slaves */
 
diff --git a/ldap/servers/slapd/utf8.c b/ldap/servers/slapd/utf8.c
index dac5219..b0667c6 100644
--- a/ldap/servers/slapd/utf8.c
+++ b/ldap/servers/slapd/utf8.c
@@ -68,20 +68,30 @@ ldap_utf8next(char *s)
     switch (UTF8len[(*next >> 2) & 0x3F]) {
     case 0: /* erroneous: s points to the middle of a character. */
     case 6:
-        if ((*++next & 0xC0) != 0x80)
+        if ((*++next & 0xC0) != 0x80) {
             break;
+        }
+        /* FALLTHRU */
     case 5:
-        if ((*++next & 0xC0) != 0x80)
+        if ((*++next & 0xC0) != 0x80) {
             break;
+        }
+        /* FALLTHRU */
     case 4:
-        if ((*++next & 0xC0) != 0x80)
+        if ((*++next & 0xC0) != 0x80) {
             break;
+        }
+        /* FALLTHRU */
     case 3:
-        if ((*++next & 0xC0) != 0x80)
+        if ((*++next & 0xC0) != 0x80) {
             break;
+        }
+        /* FALLTHRU */
     case 2:
-        if ((*++next & 0xC0) != 0x80)
+        if ((*++next & 0xC0) != 0x80) {
             break;
+        }
+        /* FALLTHRU */
     case 1:
         ++next;
     }
@@ -161,24 +171,34 @@ ldap_utf8copy(char *dst, const char *src)
     case 0: /* erroneous: s points to the middle of a character. */
     case 6:
         *dst++ = *s++;
-        if ((*s & 0xC0) != 0x80)
+        if ((*s & 0xC0) != 0x80) {
             break;
+        }
+        /* FALLTHRU */
     case 5:
         *dst++ = *s++;
-        if ((*s & 0xC0) != 0x80)
+        if ((*s & 0xC0) != 0x80) {
             break;
+        }
+        /* FALLTHRU */
     case 4:
         *dst++ = *s++;
-        if ((*s & 0xC0) != 0x80)
+        if ((*s & 0xC0) != 0x80) {
             break;
+        }
+        /* FALLTHRU */
     case 3:
         *dst++ = *s++;
-        if ((*s & 0xC0) != 0x80)
+        if ((*s & 0xC0) != 0x80) {
             break;
+        }
+        /* FALLTHRU */
     case 2:
         *dst++ = *s++;
-        if ((*s & 0xC0) != 0x80)
+        if ((*s & 0xC0) != 0x80) {
             break;
+        }
+        /* FALLTHRU */
     case 1:
         *dst = *s++;
     }
diff --git a/src/libsds/test/test_sds_bpt.c b/src/libsds/test/test_sds_bpt.c
index 8c2b098..b450109 100644
--- a/src/libsds/test/test_sds_bpt.c
+++ b/src/libsds/test/test_sds_bpt.c
@@ -162,6 +162,7 @@ test_9_insert_fill_and_split(void **state)
     }
 }
 
+#ifdef SDS_DEBUG
 static void
 test_10_tamper_with_inst(void **state __attribute__((unused)))
 {
@@ -183,7 +184,9 @@ test_10_tamper_with_inst(void **state __attribute__((unused)))
     /* If this reports unknown, it means we may not have freed some nodes. */
     assert_int_equal(result, SDS_SUCCESS);
 }
+#endif
 
+#ifdef SDS_DEBUG
 static void
 test_11_tamper_with_node(void **state __attribute__((unused)))
 {
@@ -198,14 +201,13 @@ test_11_tamper_with_node(void **state __attribute__((unused)))
 
     binst->root->keys[0] = (void *)1;
 
-#ifdef SDS_DEBUG
     result = sds_bptree_verify(binst);
     assert_int_equal(result, SDS_CHECKSUM_FAILURE);
-#endif
 
     result = sds_bptree_destroy(binst);
     assert_int_equal(result, SDS_SUCCESS);
 }
+#endif
 
 static void
 test_12_insert_fill_split_and_grow(void **state)
-- 
1.8.3.1

