[Fedora-directory-commits] ldapserver/ldap/servers/plugins/chainingdb cb_instance.c, 1.9, 1.10

Richard Allen Megginson rmeggins at fedoraproject.org
Wed Oct 8 17:29:04 UTC 2008


Author: rmeggins

Update of /cvs/dirsec/ldapserver/ldap/servers/plugins/chainingdb
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv26931/ldapserver/ldap/servers/plugins/chainingdb

Modified Files:
	cb_instance.c 
Log Message:
Bug Description: Need to address 64-bit compiler warnings - part 1
Reviewed by: nhosoi (Thanks!)
Fix Description: The intptr_t and uintptr_t are types which are defined as integer types that are the same size as the pointer (void *) type.  On the platforms we currently support, this is the same as long and unsigned long, respectively (ILP32 and LP64).  However, intptr_t and uintptr_t are more portable.  These can be used to assign a value passed as a void * to get an integer value, then "cast down" to an int or PRBool, and vice versa.  This seems to be a common idiom in other applications where values must be passed as void *.
For the printf/scanf formats, there is a standard header called inttypes.h which defines formats to use for various 64 bit quantities, so that you don't need to figure out if you have to use %lld or %ld for a 64-bit value - you just use PRId64 which is set to the correct value.  I also assumed that size_t is defined as the same size as a pointer so I used the PRIuPTR format macro for size_t.
I removed many unused variables and some unused functions.
I put parentheses around assignments in conditional expressions to tell the compiler not to complain about them.
I cleaned up some #defines that were defined more than once.
I commented out some unused goto labels.
Some of our header files shared among several source files define static variables.  I made it so that those variables are not defined unless a macro is set in the source file.  This avoids a lot of unused variable warnings.
I added some return values to functions that were declared as returning a value but did not return a value.  In all of these cases no one was checking the return value anyway.
I put explicit parentheses around cases like this: expr || expr && expr - the && has greater precedence than the ||.  The compiler complains because it wants you to make sure you mean expr || (expr && expr), not (expr || expr) && expr.
I cleaned up several places where the compiler was complaining about possible use of uninitialized variables.  There are still a lot of these cases remaining.
There are a lot of warnings like this:
lib/ldaputil/certmap.c:1279: warning: dereferencing type-punned pointer will break strict-aliasing rules
These are due to our use of void ** to pass in addresses of addresses of structures.  Many of these are calls to slapi_ch_free, but many are not - they are cases where we do not know what the type is going to be and may have to cast and modify the structure or pointer.  I started replacing the calls to slapi_ch_free with slapi_ch_free_string, but there are many many more that need to be fixed.
The dblayer code also contains a fix for https://bugzilla.redhat.com/show_bug.cgi?id=463991 - instead of checking for dbenv->foo_handle to see if a db "feature" is enabled, instead check the flags passed to open the dbenv.  This works for bdb 4.2 through bdb 4.7 and probably other releases as well.
Platforms tested: RHEL5 x86_64, Fedora 8 i386
Flag Day: no
Doc impact: no



Index: cb_instance.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/plugins/chainingdb/cb_instance.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- cb_instance.c	27 Jun 2008 19:28:22 -0000	1.9
+++ cb_instance.c	8 Oct 2008 17:29:01 -0000	1.10
@@ -903,7 +903,7 @@
 static void *cb_instance_sizelimit_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-	int data;
+	uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock);
 	data = inst->sizelimit;
@@ -916,10 +916,10 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
         	PR_RWLock_Wlock(inst->rwl_config_lock);
-		inst->sizelimit=(int) value;
+            inst->sizelimit=(int) ((uintptr_t)value);
         	PR_RWLock_Unlock(inst->rwl_config_lock);
 		if (inst->inst_be) 
-			be_set_sizelimit(inst->inst_be, (int) value);
+			be_set_sizelimit(inst->inst_be, (int) ((uintptr_t)value));
 	}
 	return LDAP_SUCCESS;
 }
@@ -927,7 +927,7 @@
 static void *cb_instance_timelimit_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-	int data;
+	uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock);
 	data = inst->timelimit;
@@ -940,10 +940,10 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
         	PR_RWLock_Wlock(inst->rwl_config_lock);
-		inst->timelimit=(int) value;
+		inst->timelimit=(int) ((uintptr_t)value);
         	PR_RWLock_Unlock(inst->rwl_config_lock);
 		if (inst->inst_be) 
-			be_set_timelimit(inst->inst_be, (int) value);
+			be_set_timelimit(inst->inst_be, (int) ((uintptr_t)value));
 	}
 	return LDAP_SUCCESS;
 }
@@ -951,7 +951,7 @@
 static void *cb_instance_max_test_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-	int data;
+	uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock);
 	data = inst->max_test_time;
@@ -964,7 +964,7 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
         	PR_RWLock_Wlock(inst->rwl_config_lock);
-		inst->max_test_time=(int) value;
+		inst->max_test_time=(int) ((uintptr_t)value);
         	PR_RWLock_Unlock(inst->rwl_config_lock);
 	}
 	return LDAP_SUCCESS;
@@ -973,7 +973,7 @@
 static void *cb_instance_max_idle_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-	int data;
+	uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock);
 	data = inst->max_idle_time;
@@ -986,7 +986,7 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
         	PR_RWLock_Wlock(inst->rwl_config_lock);
-		inst->max_idle_time=(int) value;
+		inst->max_idle_time=(int) ((uintptr_t)value);
         	PR_RWLock_Unlock(inst->rwl_config_lock);
 	}
 	return LDAP_SUCCESS;
@@ -996,7 +996,7 @@
 static void *cb_instance_hoplimit_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-	int data;
+	uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock);
 	data = inst->hoplimit;
@@ -1009,7 +1009,7 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
         	PR_RWLock_Wlock(inst->rwl_config_lock);
-		inst->hoplimit=(int) value;
+		inst->hoplimit=(int) ((uintptr_t)value);
         	PR_RWLock_Unlock(inst->rwl_config_lock);
 	}
 	return LDAP_SUCCESS;
@@ -1018,7 +1018,7 @@
 static void *cb_instance_maxbconn_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-	int data;
+	uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock);
 	data = inst->bind_pool->conn.maxconnections;
@@ -1031,7 +1031,7 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
         	PR_RWLock_Wlock(inst->rwl_config_lock);
-		inst->bind_pool->conn.maxconnections=(int) value;
+		inst->bind_pool->conn.maxconnections=(int) ((uintptr_t)value);
         	PR_RWLock_Unlock(inst->rwl_config_lock);
 	}
 	return LDAP_SUCCESS;
@@ -1040,7 +1040,7 @@
 static void *cb_instance_maxconn_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-	int data;
+	uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock);
 	data = inst->pool->conn.maxconnections;
@@ -1053,7 +1053,7 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
         	PR_RWLock_Wlock(inst->rwl_config_lock);
-		inst->pool->conn.maxconnections=(int) value;
+		inst->pool->conn.maxconnections=(int) ((uintptr_t)value);
         	PR_RWLock_Unlock(inst->rwl_config_lock);
 	}
 	return LDAP_SUCCESS;
@@ -1062,7 +1062,7 @@
 static void *cb_instance_abandonto_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-	int data;
+	uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock);
 	data = inst->abandon_timeout.tv_sec;
@@ -1084,7 +1084,7 @@
 		}
 
                	PR_RWLock_Wlock(inst->rwl_config_lock);
-		inst->abandon_timeout.tv_sec=(int) value;
+		inst->abandon_timeout.tv_sec=(int) ((uintptr_t)value);
 		inst->abandon_timeout.tv_usec=0;
                	PR_RWLock_Unlock(inst->rwl_config_lock);
 	}
@@ -1094,7 +1094,7 @@
 static void *cb_instance_maxbconc_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-	int data;
+	uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock);
 	data = inst->bind_pool->conn.maxconcurrency;
@@ -1107,7 +1107,7 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
         	PR_RWLock_Wlock(inst->rwl_config_lock);
-		inst->bind_pool->conn.maxconcurrency=(int) value;
+		inst->bind_pool->conn.maxconcurrency=(int) ((uintptr_t)value);
         	PR_RWLock_Unlock(inst->rwl_config_lock);
 	}
 	return LDAP_SUCCESS;
@@ -1116,7 +1116,7 @@
 static void *cb_instance_maxconc_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-	int data;
+	uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock);
 	data = inst->pool->conn.maxconcurrency;
@@ -1129,7 +1129,7 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
                 PR_RWLock_Wlock(inst->rwl_config_lock);
-		inst->pool->conn.maxconcurrency=(int) value;
+		inst->pool->conn.maxconcurrency=(int) ((uintptr_t)value);
                 PR_RWLock_Unlock(inst->rwl_config_lock);
 	}
         return LDAP_SUCCESS;   
@@ -1138,7 +1138,7 @@
 static void *cb_instance_imperson_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-        int data;
+        uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock);
         data = inst->impersonate;
@@ -1153,7 +1153,7 @@
 
 	if (apply) {
                 PR_RWLock_Wlock(inst->rwl_config_lock); 
-		inst->impersonate=(int) value;
+		inst->impersonate=(int) ((uintptr_t)value);
                 PR_RWLock_Unlock(inst->rwl_config_lock); 
 	} else {
 		/* Security check: Make sure the proxing user is */
@@ -1162,7 +1162,7 @@
 		char * rootdn=cb_get_rootdn();
 
                 PR_RWLock_Rlock(inst->rwl_config_lock); 
-		if (((int) value) && inst->pool && inst->pool->binddn &&
+		if (((int) ((uintptr_t)value)) && inst->pool && inst->pool->binddn &&
 	                !strcmp(inst->pool->binddn,rootdn)) {	/* UTF-8 aware */
 		  	rc=LDAP_UNWILLING_TO_PERFORM;
 			if (errorbuf)
@@ -1179,7 +1179,7 @@
 static void *cb_instance_connlife_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-        int data; 
+        uintptr_t data; 
  
         PR_RWLock_Rlock(inst->rwl_config_lock); 
         data=inst->pool->conn.connlifetime;
@@ -1192,7 +1192,7 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
                 PR_RWLock_Wlock(inst->rwl_config_lock);  
-		inst->pool->conn.connlifetime=(int) value;
+		inst->pool->conn.connlifetime=(int) ((uintptr_t)value);
                 PR_RWLock_Unlock(inst->rwl_config_lock);  
 	}
         return LDAP_SUCCESS;     
@@ -1201,7 +1201,7 @@
 static void *cb_instance_bindto_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-        int data;  
+        uintptr_t data;  
  
         PR_RWLock_Rlock(inst->rwl_config_lock);  
         data=inst->bind_pool->conn.op_timeout.tv_sec;
@@ -1214,12 +1214,12 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
                 PR_RWLock_Wlock(inst->rwl_config_lock);   
-		inst->bind_pool->conn.op_timeout.tv_sec=(int) value;
+		inst->bind_pool->conn.op_timeout.tv_sec=(int) ((uintptr_t)value);
 		inst->bind_pool->conn.op_timeout.tv_usec=0;
-		inst->bind_pool->conn.bind_timeout.tv_sec=(int) value;
+		inst->bind_pool->conn.bind_timeout.tv_sec=(int) ((uintptr_t)value);
 		inst->bind_pool->conn.bind_timeout.tv_usec=0;
 		/* Used to bind to the farm server */
-		inst->pool->conn.bind_timeout.tv_sec=(int) value;
+		inst->pool->conn.bind_timeout.tv_sec=(int) ((uintptr_t)value);
 		inst->pool->conn.bind_timeout.tv_usec=0;
                 PR_RWLock_Unlock(inst->rwl_config_lock);   
 	}
@@ -1229,7 +1229,7 @@
 static void *cb_instance_opto_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-        int data;  
+        uintptr_t data;  
  
         PR_RWLock_Rlock(inst->rwl_config_lock);  
         data=inst->pool->conn.op_timeout.tv_sec;
@@ -1242,7 +1242,7 @@
         cb_backend_instance * inst=(cb_backend_instance *) arg;
         if (apply) {
                 PR_RWLock_Wlock(inst->rwl_config_lock);
-                inst->pool->conn.op_timeout.tv_sec=(int) value;
+                inst->pool->conn.op_timeout.tv_sec=(int) ((uintptr_t)value);
                 inst->pool->conn.op_timeout.tv_usec=0;
                 PR_RWLock_Unlock(inst->rwl_config_lock);
         }
@@ -1252,7 +1252,7 @@
 static void *cb_instance_ref_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-        int data;   
+        uintptr_t data;   
   
         PR_RWLock_Rlock(inst->rwl_config_lock);   
         data=inst->searchreferral;
@@ -1265,7 +1265,7 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
                 PR_RWLock_Wlock(inst->rwl_config_lock);    
-		inst->searchreferral=(int) value;
+		inst->searchreferral=(int) ((uintptr_t)value);
                 PR_RWLock_Unlock(inst->rwl_config_lock);    
 	}
 	return LDAP_SUCCESS;
@@ -1274,7 +1274,7 @@
 static void *cb_instance_acl_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-        int data;
+        uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock);
         data=inst->local_acl;
@@ -1295,7 +1295,7 @@
                         return LDAP_SUCCESS;
                 }
 	        PR_RWLock_Wlock(inst->rwl_config_lock);
-		inst->local_acl=(int) value;
+		inst->local_acl=(int) ((uintptr_t)value);
 	        PR_RWLock_Unlock(inst->rwl_config_lock);
 	}
 	return LDAP_SUCCESS;
@@ -1304,7 +1304,7 @@
 static void *cb_instance_bindretry_get(void *arg)
 {
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
-	int data;
+	uintptr_t data;
 
         PR_RWLock_Rlock(inst->rwl_config_lock); 
         data=inst->bind_retry;
@@ -1317,7 +1317,7 @@
 	cb_backend_instance * inst=(cb_backend_instance *) arg;
 	if (apply) {
                 PR_RWLock_Wlock(inst->rwl_config_lock);
-		inst->bind_retry=(int) value;
+		inst->bind_retry=(int) ((uintptr_t)value);
                 PR_RWLock_Unlock(inst->rwl_config_lock);
 	}
 	return LDAP_SUCCESS;
@@ -1383,7 +1383,7 @@
                 } else {
                         int_val = cb_atoi((char *)bval->bv_val);
                 }
-                retval = config->config_set_fn(arg, (void *) int_val, err_buf, phase, apply_mod);
+                retval = config->config_set_fn(arg, (void *) ((uintptr_t)int_val), err_buf, phase, apply_mod);
                 break;
         case CB_CONFIG_TYPE_INT_OCTAL:
                 if (use_default) {
@@ -1391,7 +1391,7 @@
                 } else {
                         int_val = (int) strtol((char *)bval->bv_val, NULL, 8);
                 }
-                retval = config->config_set_fn(arg, (void *) int_val, err_buf, phase, apply_mod);
+                retval = config->config_set_fn(arg, (void *) ((uintptr_t)int_val), err_buf, phase, apply_mod);
                 break;
         case CB_CONFIG_TYPE_LONG:
                 if (use_default) {
@@ -1414,7 +1414,7 @@
                 } else {
                         int_val = !strcasecmp((char *) bval->bv_val, "on");
                 }
-                retval = config->config_set_fn(arg, (void *) int_val, err_buf, phase, apply_mod);
+                retval = config->config_set_fn(arg, (void *) ((uintptr_t)int_val), err_buf, phase, apply_mod);
                 break;
         }        
         return retval;
@@ -1435,10 +1435,10 @@
  
         switch(config->config_type) {
         case CB_CONFIG_TYPE_INT:
-                sprintf(buf, "%d", (int) config->config_get_fn(arg));
+                sprintf(buf, "%d", (int) ((uintptr_t)config->config_get_fn(arg)));
                 break;
         case CB_CONFIG_TYPE_INT_OCTAL:
-                sprintf(buf, "%o", (int) config->config_get_fn(arg));
+                sprintf(buf, "%o", (int) ((uintptr_t)config->config_get_fn(arg)));
                 break;
         case CB_CONFIG_TYPE_LONG:
                 sprintf(buf, "%ld", (long) config->config_get_fn(arg));
@@ -1451,7 +1451,7 @@
                 slapi_ch_free((void **)&tmp_string);
                 break;
         case CB_CONFIG_TYPE_ONOFF:
-                if ((int) config->config_get_fn(arg)) {
+                if ((int) ((uintptr_t)config->config_get_fn(arg))) {
                         sprintf(buf,"%s","on");
                 } else {
                         sprintf(buf,"%s","off");




More information about the Fedora-directory-commits mailing list