Author: rmeggins
Update of /cvs/dirsec/ldapserver/ldap/servers/plugins/dna In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv26931/ldapserver/ldap/servers/plugins/dna
Modified Files: dna.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: dna.c =================================================================== RCS file: /cvs/dirsec/ldapserver/ldap/servers/plugins/dna/dna.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- dna.c 3 Oct 2008 04:28:21 -0000 1.10 +++ dna.c 8 Oct 2008 17:29:02 -0000 1.11 @@ -55,6 +55,13 @@ #include "prclist.h" #include "ldif.h"
+/* Required to get portable printf/scanf format macros */ +#ifdef HAVE_INTTYPES_H +#include <inttypes.h> +#else +#error Need to define portable format macros such as PRIu64 +#endif /* HAVE_INTTYPES_H */ + /* get file mode flags for unix */ #ifndef _WIN32 #include <sys/stat.h> @@ -708,7 +715,7 @@ }
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM, - "----------> %s [%llu]\n", DNA_NEXTVAL, entry->nextval, 0, + "----------> %s [%" PRIu64 "]\n", DNA_NEXTVAL, entry->nextval, 0, 0);
value = slapi_entry_attr_get_charptr(e, DNA_PREFIX); @@ -736,7 +743,7 @@ }
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM, - "----------> %s [%llu]\n", DNA_INTERVAL, entry->interval, 0, 0); + "----------> %s [%" PRIu64 "]\n", DNA_INTERVAL, entry->interval, 0, 0); #endif
value = slapi_entry_attr_get_charptr(e, DNA_GENERATE); @@ -844,7 +851,7 @@ entry->threshold = strtoull(value, 0, 0);
slapi_log_error(SLAPI_LOG_CONFIG, DNA_PLUGIN_SUBSYSTEM, - "----------> %s [%llu]\n", DNA_THRESHOLD, value, 0, 0); + "----------> %s [%" PRIu64 "]\n", DNA_THRESHOLD, value, 0, 0);
slapi_ch_free_string(&value); } else { @@ -1319,8 +1326,8 @@ * don't need to do this if we already have a next range on deck. */ if ((config_entry->next_range_lower == 0) && (config_entry->remaining <= config_entry->threshold)) { slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM, - "dna_notice_allocation: Passed threshold of %llu remaining values " - "for range %s. (%llu values remain)\n", + "dna_notice_allocation: Passed threshold of %" PRIu64 " remaining values " + "for range %s. (%" PRIu64 " values remain)\n", config_entry->threshold, config_entry->dn, config_entry->remaining); /* Only attempt to fix maxval if the fix flag is set. */ if (fix != 0) { @@ -1461,13 +1468,11 @@ struct dnaServer *server, PRUint64 *lower, PRUint64 *upper) { - Slapi_DN *agmt_sdn = NULL; char *bind_dn = NULL; char *bind_passwd = NULL; char *bind_method = NULL; int is_ssl = 0; int is_client_auth = 0; - int replport = 0; struct berval *request = NULL; char *retoid = NULL; struct berval *responsedata = NULL; @@ -1767,12 +1772,12 @@ if (prefix) { /* The 7 below is for all of the filter characters "(&(=))" * plus the trailing \0. The 20 is for the maximum string - * representation of a %llu. */ + * representation of a " PRIu64 ". */ filterlen = strlen(config_entry->filter) + strlen(prefix) + strlen(type) + 7 + 20; filter = slapi_ch_malloc(filterlen); - snprintf(filter, filterlen, "(&%s(%s=%s%llu))", + snprintf(filter, filterlen, "(&%s(%s=%s%" PRIu64 "))", config_entry->filter, type, prefix, tmpval); } else { ctrls = (LDAPControl **)slapi_ch_calloc(2, sizeof(LDAPControl)); @@ -1785,7 +1790,7 @@ return LDAP_OPERATIONS_ERROR; }
- filter = slapi_ch_smprintf("(&%s(&(%s>=%llu)(%s<=%llu)))", + filter = slapi_ch_smprintf("(&%s(&(%s>=%" PRIu64 ")(%s<=%" PRIu64 ")))", config_entry->filter, type, tmpval, type, config_entry->maxval); @@ -1836,7 +1841,7 @@ /* filter is guaranteed to be big enough since we allocated * enough space to fit a string representation of any unsigned * 64-bit integer */ - snprintf(filter, filterlen, "(&%s(%s=%s%llu))", + snprintf(filter, filterlen, "(&%s(%s=%s%" PRIu64 "))", config_entry->filter, type, prefix, tmpval);
/* clear out the pblock so we can re-use it */ @@ -1968,7 +1973,7 @@ * of our current range */ if (nextval <= (config_entry->maxval + config_entry->interval)) { /* try to set the new next value in the config entry */ - snprintf(next_value, sizeof(next_value),"%llu", nextval); + snprintf(next_value, sizeof(next_value),"%" PRIu64, nextval);
/* set up our replace modify operation */ replace_val[0] = next_value; @@ -1998,7 +2003,7 @@
if (LDAP_SUCCESS == ret) { slapi_ch_free_string(next_value_ret); - *next_value_ret = slapi_ch_smprintf("%llu", setval); + *next_value_ret = slapi_ch_smprintf("%" PRIu64, setval); if (NULL == *next_value_ret) { ret = LDAP_OPERATIONS_ERROR; goto done; @@ -2045,7 +2050,7 @@
/* We store the number of remaining assigned values * in the shared config entry. */ - snprintf(remaining_vals, sizeof(remaining_vals),"%llu", config_entry->remaining); + snprintf(remaining_vals, sizeof(remaining_vals),"%" PRIu64, config_entry->remaining);
/* set up our replace modify operation */ replace_val[0] = remaining_vals; @@ -2130,7 +2135,7 @@ int ret = 0;
/* Try to set the new next range in the config entry. */ - snprintf(nextrange_value, sizeof(nextrange_value), "%llu-%llu", + snprintf(nextrange_value, sizeof(nextrange_value), "%" PRIu64 "-%" PRIu64, lower, upper);
/* set up our replace modify operation */ @@ -2199,8 +2204,8 @@ int ret = 0;
/* Setup the modify operation for the config entry */ - snprintf(maxval_val, sizeof(maxval_val),"%llu", config_entry->next_range_upper); - snprintf(nextval_val, sizeof(nextval_val),"%llu", config_entry->next_range_lower); + snprintf(maxval_val, sizeof(maxval_val),"%" PRIu64, config_entry->next_range_upper); + snprintf(nextval_val, sizeof(nextval_val),"%" PRIu64, config_entry->next_range_lower);
maxval_vals[0] = maxval_val; maxval_vals[1] = 0; @@ -2817,8 +2822,8 @@ char highstr[16];
/* Create the exop response */ - snprintf(lowstr, sizeof(lowstr), "%llu", lower); - snprintf(highstr, sizeof(highstr), "%llu", upper); + snprintf(lowstr, sizeof(lowstr), "%" PRIu64, lower); + snprintf(highstr, sizeof(highstr), "%" PRIu64, upper); range_low.bv_val = lowstr; range_low.bv_len = strlen(range_low.bv_val); range_high.bv_val = highstr; @@ -2846,12 +2851,12 @@ slapi_pblock_set(pb, SLAPI_EXT_OP_RET_VALUE, respdata);
/* send the response ourselves */ - send_ldap_result( pb, ret, NULL, NULL, 0, NULL ); + slapi_send_ldap_result( pb, ret, NULL, NULL, 0, NULL ); ret = SLAPI_PLUGIN_EXTENDED_SENT_RESULT; ber_bvfree(respdata);
slapi_log_error(SLAPI_LOG_PLUGIN, DNA_PLUGIN_SUBSYSTEM, - "dna_extend_exop: Released range %llu-%llu.\n", + "dna_extend_exop: Released range %" PRIu64 "-%" PRIu64 ".\n", lower, upper); }
@@ -2993,7 +2998,7 @@ *lower = *upper - release + 1;
/* try to set the new maxval in the config entry */ - snprintf(max_value, sizeof(max_value),"%llu", (*lower - 1)); + snprintf(max_value, sizeof(max_value),"%" PRIu64, (*lower - 1));
/* set up our replace modify operation */ replace_val[0] = max_value; @@ -3092,11 +3097,11 @@ printf("<---- filter ---------> %s\n", entry->filter); printf("<---- prefix ---------> %s\n", entry->prefix); printf("<---- scope ----------> %s\n", entry->scope); - printf("<---- next value -----> %llu\n", entry->nextval); - printf("<---- max value ------> %llu\n", entry->maxval); - printf("<---- interval -------> %llu\n", entry->interval); + printf("<---- next value -----> %" PRIu64 "\n", entry->nextval); + printf("<---- max value ------> %" PRIu64 "\n", entry->maxval); + printf("<---- interval -------> %" PRIu64 "\n", entry->interval); printf("<---- generate flag --> %s\n", entry->generate); printf("<---- shared cfg base > %s\n", entry->shared_cfg_base); printf("<---- shared cfg DN --> %s\n", entry->shared_cfg_dn); - printf("<---- threshold -----> %llu", entry->threshold); + printf("<---- threshold ------> %" PRIu64 "", entry->threshold); }
389-commits@lists.fedoraproject.org