Browse Source

Ticket 49275 - shadow warnings for gcc7 - pass 1

Bug Description:  Shadow variables are where we redeclare a var
of the same name in a child scope. In C this leads to a new var
being created, but often represents a fault of the developer
where they may have intended to use the outer scope.

Fix Description:  Rename inner variables, move some from
globals to stack in functions.

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

Author: wibrown

Review by: mreynolds (Thanks!)
William Brown 8 years ago
parent
commit
161cc239df

+ 5 - 4
ldap/servers/slapd/add.c

@@ -631,18 +631,19 @@ static void op_shared_add (Slapi_PBlock *pb)
                 slapi_entry_attr_find(e, L_normalized, &attr);
                 if (attr)
                 {
-                    Slapi_Value **present_values = NULL;
+                    Slapi_Value **decode_present_values = NULL;
                     Slapi_Value **vals = NULL;
 
-                    present_values= attr_get_present_values(attr);
+                    decode_present_values= attr_get_present_values(attr);
 
-                    valuearray_add_valuearray(&vals, present_values, 0);
+                    valuearray_add_valuearray(&vals, decode_present_values, 0);
                     pw_rever_encode(vals, L_normalized);
                     slapi_entry_attr_replace_sv(e, L_normalized, vals);
                     valuearray_free(&vals);
                 }
-                if (L_normalized)
+                if (L_normalized) {
                     slapi_ch_free ((void**)&L_normalized);
+                }
             }
         }
     }

+ 5 - 3
ldap/servers/slapd/entry.c

@@ -1114,9 +1114,11 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
 		}
 		else
 		{
-			int flags = SLAPI_VALUE_FLAG_PASSIN;
-			if (check_for_duplicate_values) flags |= SLAPI_VALUE_FLAG_DUPCHECK;
-			rc = slapi_valueset_add_attr_value_ext(&sa->sa_attr, &sa->sa_present_values,value, flags);
+			int value_flags = SLAPI_VALUE_FLAG_PASSIN;
+			if (check_for_duplicate_values) {
+				value_flags |= SLAPI_VALUE_FLAG_DUPCHECK;
+			}
+			rc = slapi_valueset_add_attr_value_ext(&sa->sa_attr, &sa->sa_present_values,value, value_flags);
 		}
 
 		if ( rc==LDAP_SUCCESS )

+ 4 - 4
ldap/servers/slapd/entrywsi.c

@@ -677,10 +677,10 @@ entry_delete_present_values_wsi(Slapi_Entry *e, const char *type, struct berval
                          * The attribute would otherwise be created in the 
                          * entry_add_.. function
                          */
-			Slapi_Attr *a = slapi_attr_new();
-			slapi_attr_init(a, type);
-			attr_set_deletion_csn(a,csn); 
-			entry_add_deleted_attribute_wsi(e, a);
+			Slapi_Attr *create_a = slapi_attr_new();
+			slapi_attr_init(create_a, type);
+			attr_set_deletion_csn(create_a,csn);
+			entry_add_deleted_attribute_wsi(e, create_a);
 		}
 	}
 	return retVal;

File diff suppressed because it is too large
+ 227 - 223
ldap/servers/slapd/main.c


+ 12 - 12
ldap/servers/slapd/modify.c

@@ -636,7 +636,7 @@ static void op_shared_modify (Slapi_PBlock *pb, int pw_change, char *old_pw)
 	int err;
 	LDAPMod *lc_mod = NULL;
 	struct slapdplugin  *p = NULL;
-	int numattr, i;
+	int numattr;
 	char *proxydn = NULL;
 	int proxy_err = LDAP_SUCCESS;
 	char *errtext = NULL;
@@ -761,7 +761,7 @@ static void op_shared_modify (Slapi_PBlock *pb, int pw_change, char *old_pw)
 				if ((*tmpmods)->mod_bvalues != NULL &&
 				    !SLAPI_IS_MOD_DELETE((*tmpmods)->mod_op))
 				{
-					for (i=0; i < numattr; i++)
+					for (size_t i=0; i < numattr; i++)
 					{
 						if (slapi_attr_type_cmp((*tmpmods)->mod_type, 
 							AttrValueCheckList[i].attr_name, SLAPI_TYPE_CMP_SUBTYPE) == 0)
@@ -829,7 +829,7 @@ static void op_shared_modify (Slapi_PBlock *pb, int pw_change, char *old_pw)
 				char *valpwd = NULL;
 
 				/* if there are mod values, we need to delete a specific userpassword */
-				for ( i = 0; pw_mod->mod_bvalues != NULL && pw_mod->mod_bvalues[i] != NULL; i++ ) {
+				for (size_t i = 0; pw_mod->mod_bvalues != NULL && pw_mod->mod_bvalues[i] != NULL; i++ ) {
 					password = slapi_ch_strdup(pw_mod->mod_bvalues[i]->bv_val);
 					pwsp = pw_val2scheme( password, &valpwd, 1 );
 					if(pwsp == NULL || strcmp(pwsp->pws_name, "CLEAR") == 0){
@@ -982,7 +982,7 @@ static void op_shared_modify (Slapi_PBlock *pb, int pw_change, char *old_pw)
 	for ( p = get_plugin_list(PLUGIN_LIST_REVER_PWD_STORAGE_SCHEME); p != NULL && !repl_op; p = p->plg_next )
     {
         char *L_attr = NULL;
-        int i = 0;
+        size_t i = 0;
  
         /* Get the appropriate encoding function */
         for ( L_attr = p->plg_argv[i]; i<p->plg_argc; L_attr = p->plg_argv[++i])
@@ -1153,17 +1153,16 @@ free_and_return:
 static int
 valuearray_init_bervalarray_unhashed_only(struct berval **bvals, Slapi_Value ***cvals)
 {
-	int n;
-
+	size_t n;
 	for(n=0; bvals != NULL && bvals[n] != NULL; n++);
 	if(n==0){
 		*cvals = NULL;
 	} else {
 		struct pw_scheme *pwsp = NULL;
-		int i,p;
+		size_t p = 0;
 
 		*cvals = (Slapi_Value **) slapi_ch_malloc((n + 1) * sizeof(Slapi_Value *));
-		for(i=0,p=0;i<n;i++){
+		for(size_t i=0; i<n; i++){
 			pwsp = pw_val2scheme( bvals[i]->bv_val, NULL, 1 );
 			if(pwsp == NULL || strcmp(pwsp->pws_name, "CLEAR") == 0){
 				(*cvals)[p++] = slapi_value_new_berval(bvals[i]);
@@ -1434,7 +1433,6 @@ done:
 static int
 hash_rootpw (LDAPMod **mods)
 {
-	int i, j;
 	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
 
 	if (strcasecmp(slapdFrontendConfig->rootpwstoragescheme->pws_name, "clear") == 0) {
@@ -1442,13 +1440,13 @@ hash_rootpw (LDAPMod **mods)
 		return 0;
 	}
 
-	for (i=0; (mods != NULL) && (mods[i] != NULL); i++) {
+	for (size_t i=0; (mods != NULL) && (mods[i] != NULL); i++) {
 		LDAPMod *mod = mods[i];
 		if (strcasecmp (mod->mod_type, CONFIG_ROOTPW_ATTRIBUTE) != 0) 
 			continue;
 
 		if (mod->mod_bvalues != NULL) {
-			for (j = 0; mod->mod_bvalues[j] != NULL; j++) {
+			for (size_t j = 0; mod->mod_bvalues[j] != NULL; j++) {
 				char *val = mod->mod_bvalues[j]->bv_val;
 				char *hashedval = NULL;
 				struct pw_scheme *pws = pw_val2scheme (val, NULL, 0);
@@ -1503,7 +1501,9 @@ hash_rootpw (LDAPMod **mods)
 static void
 optimize_mods(Slapi_Mods *smods){
     LDAPMod *mod, *prev_mod;
-    int i, mod_count = 0, max_vals = 0;
+    int mod_count = 0;
+    int max_vals = 0;
+    size_t i = 0;
 
     prev_mod = slapi_mods_get_first_mod(smods);
     while((mod = slapi_mods_get_next_mod(smods))){

+ 16 - 16
ldap/servers/slapd/ssl.c

@@ -686,25 +686,25 @@ _conf_dumpciphers(void)
 }
 
 char *
-_conf_setciphers(char *ciphers, int flags)
+_conf_setciphers(char *setciphers, int flags)
 {
     char *t, err[MAGNUS_ERROR_LEN];
     int x, i, active;
-    char *raw = ciphers;
+    char *raw = setciphers;
     char **suplist = NULL;
     char **unsuplist = NULL;
     PRBool enabledOne = PR_FALSE;
 
     /* #47838: harden the list of ciphers available by default */
     /* Default is to activate all of them ==> none of them*/
-    if (!ciphers || (ciphers[0] == '\0') || !PL_strcasecmp(ciphers, "default")) {
+    if (!setciphers || (setciphers[0] == '\0') || !PL_strcasecmp(setciphers, "default")) {
         _conf_setallciphers((CIPHER_SET_DEFAULT|flags), NULL, NULL);
         slapd_SSL_info("Enabling default cipher set.");
         _conf_dumpciphers();
         return NULL;
     }
 
-    if (PL_strcasestr(ciphers, "+all")) {
+    if (PL_strcasestr(setciphers, "+all")) {
         /*
          * Enable all the ciphers if "+all" and the following while loop would
          * disable the user disabled ones.  This is needed because we added a new
@@ -719,11 +719,11 @@ _conf_setciphers(char *ciphers, int flags)
         _conf_setallciphers(CIPHER_SET_NONE /* disabled */, NULL, NULL);
     }
 
-    t = ciphers;
+    t = setciphers;
     while(t) {
-        while((*ciphers) && (isspace(*ciphers))) ++ciphers;
+        while((*setciphers) && (isspace(*setciphers))) ++setciphers;
 
-        switch(*ciphers++) {
+        switch(*setciphers++) {
           case '+':
             active = 1; break;
           case '-':
@@ -733,14 +733,14 @@ _conf_setciphers(char *ciphers, int flags)
                     "+cipher1,-cipher2...", raw);
             return slapi_ch_strdup(err);
         }
-        if( (t = strchr(ciphers, ',')) )
+        if( (t = strchr(setciphers, ',')) )
             *t++ = '\0';
 
-        if (strcasecmp(ciphers, "all")) { /* if not all */
+        if (strcasecmp(setciphers, "all")) { /* if not all */
             PRBool enabled = active ? PR_TRUE : PR_FALSE;
             int lookup = 1;
             for (x = 0; _conf_ciphers[x].name; x++) {
-                if (!PL_strcasecmp(ciphers, _conf_ciphers[x].name)) {
+                if (!PL_strcasecmp(setciphers, _conf_ciphers[x].name)) {
                     if (_conf_ciphers[x].flags & CIPHER_IS_WEAK) {
                         if (active && CIPHER_SET_ALLOWSWEAKCIPHER(flags)) { 
                             slapd_SSL_warn("Cipher %s is weak.  It is enabled since allowWeakCipher is \"on\" "
@@ -748,7 +748,7 @@ _conf_setciphers(char *ciphers, int flags)
                                            "We strongly recommend to set it to \"off\".  "
                                            "Please replace the value of allowWeakCipher with \"off\" in "
                                            "the encryption config entry cn=encryption,cn=config and "
-                                           "restart the server.", ciphers);
+                                           "restart the server.", setciphers);
                         } else {
                             /* if the cipher is weak and we don't allow weak cipher,
                                disable it. */
@@ -770,10 +770,10 @@ _conf_setciphers(char *ciphers, int flags)
             }
             if (lookup) { /* lookup with old cipher name and get NSS cipherSuiteName */
                 for (i = 0; _lookup_cipher[i].alias; i++) {
-                    if (!PL_strcasecmp(ciphers, _lookup_cipher[i].alias)) {
+                    if (!PL_strcasecmp(setciphers, _lookup_cipher[i].alias)) {
                         if (enabled && !_lookup_cipher[i].name[0]) {
                             slapd_SSL_warn("Cipher suite %s is not available in NSS %d.%d.  Ignoring %s",
-                                           ciphers, NSS_VMAJOR, NSS_VMINOR, ciphers);
+                                           setciphers, NSS_VMAJOR, NSS_VMINOR, setciphers);
                             continue;
                         }
                         for (x = 0; _conf_ciphers[x].name; x++) {
@@ -787,7 +787,7 @@ _conf_setciphers(char *ciphers, int flags)
                                                            "We strongly recommend to set it to \"off\".  "
                                                            "Please replace the value of allowWeakCipher with \"off\" in "
                                                            "the encryption config entry cn=encryption,cn=config and "
-                                                           "restart the server.", ciphers);
+                                                           "restart the server.", setciphers);
                                         } else {
                                             /* if the cipher is weak and we don't allow weak cipher,
                                                disable it. */
@@ -813,11 +813,11 @@ _conf_setciphers(char *ciphers, int flags)
             }
             if (!lookup && !_conf_ciphers[x].name) { /* If lookup, it's already reported. */
                 slapd_SSL_warn("Cipher suite %s is not available in NSS %d.%d.  Ignoring %s",
-                               ciphers, NSS_VMAJOR, NSS_VMINOR, ciphers);
+                               setciphers, NSS_VMAJOR, NSS_VMINOR, setciphers);
             }
         }
         if(t) {
-            ciphers = t;
+            setciphers = t;
         }
     }
     if (unsuplist && *unsuplist) {

+ 2 - 2
lib/ldaputil/certmap.c

@@ -1433,9 +1433,9 @@ static void * ldapu_certinfo_free_helper (void *info, void *arg __attribute__((u
     return (void *)LDAPU_SUCCESS;
 }
 
-void ldapu_certmap_listinfo_free (void *certmap_listinfo)
+void ldapu_certmap_listinfo_free (void *_certmap_listinfo)
 {
-    LDAPUCertMapListInfo_t *list = (LDAPUCertMapListInfo_t *)certmap_listinfo;
+    LDAPUCertMapListInfo_t *list = (LDAPUCertMapListInfo_t *)_certmap_listinfo;
     ldapu_list_free(list, ldapu_certinfo_free_helper);
 }
 

Some files were not shown because too many files changed in this diff