From b3797a8704696ed77b69a042e75ce5553e24b68b Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Wed, 8 Oct 2008 17:29:05 +0000 Subject: 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 --- lib/ldaputil/certmap.c | 8 ++++++-- lib/ldaputil/ldapauth.c | 1 + lib/ldaputil/ldapdb.c | 3 +++ lib/libaccess/aclerror.cpp | 2 +- lib/libaccess/acltools.cpp | 2 +- lib/libaccess/lasdns.cpp | 4 ++-- lib/libaccess/lasip.cpp | 4 ++-- lib/libaccess/ldapacl.cpp | 2 +- lib/libaccess/oneeval.cpp | 4 ++-- lib/libsi18n/getstrmem.h | 10 ---------- lib/libsi18n/gsslapd.h | 8 ++++---- 11 files changed, 23 insertions(+), 25 deletions(-) (limited to 'lib') diff --git a/lib/ldaputil/certmap.c b/lib/ldaputil/certmap.c index 57d1f910..cea403b6 100644 --- a/lib/ldaputil/certmap.c +++ b/lib/ldaputil/certmap.c @@ -55,6 +55,7 @@ #include #include +#define DEFINE_LDAPU_STRINGS 1 #include #include #include @@ -300,7 +301,8 @@ static int ldapu_list_print (LDAPUList_t *list, LDAPUListNodeFn_t print_fn, int rv; while(node) { - rv = (int)(*print_fn)(node->info, pinfo); + uintptr_t retval = (uintptr_t)(*print_fn)(node->info, pinfo); + rv = (int)retval; if (rv != LDAPU_SUCCESS) return rv; node = node->next; } @@ -1691,6 +1693,7 @@ NSAPI_PUBLIC int ldapu_certinfo_save (const char *fname, char *ptr; int eof; int rv; + uintptr_t retval; LDAPUPrintInfo_t pinfo; #ifdef XP_WIN32 @@ -1730,7 +1733,8 @@ NSAPI_PUBLIC int ldapu_certinfo_save (const char *fname, pinfo.fp = tfp; pinfo.arg = default_certmap_info->issuerName; - rv = (int)ldapu_certinfo_print (default_certmap_info, &pinfo); + retval = (uintptr_t)ldapu_certinfo_print (default_certmap_info, &pinfo); + rv = (int)retval; if (rv != LDAPU_SUCCESS) { fclose(tfp); diff --git a/lib/ldaputil/ldapauth.c b/lib/ldaputil/ldapauth.c index 0039bae5..b483e42f 100644 --- a/lib/ldaputil/ldapauth.c +++ b/lib/ldaputil/ldapauth.c @@ -53,6 +53,7 @@ #include #include +#define DEFINE_LDAPU_STRINGS 1 #include #include #include diff --git a/lib/ldaputil/ldapdb.c b/lib/ldaputil/ldapdb.c index a126c169..478b4f8c 100644 --- a/lib/ldaputil/ldapdb.c +++ b/lib/ldaputil/ldapdb.c @@ -171,7 +171,10 @@ ldapu_gethostbyaddr( const char *addr, int length, int type, LDAPHostEnt *result, char *buffer, int buflen, int *statusp, void *extradata ) { + /* old code did this which was clearly wrong: return( (LDAPHostEnt *)PR_GetError() ); + which leads me to believe this is not used */ + return( NULL ); } #endif /* LDAP_OPT_DNS_FN_PTRS */ diff --git a/lib/libaccess/aclerror.cpp b/lib/libaccess/aclerror.cpp index 7c1d4a26..8e94f642 100644 --- a/lib/libaccess/aclerror.cpp +++ b/lib/libaccess/aclerror.cpp @@ -100,7 +100,7 @@ char * ACL_Program = "NSACL"; /* ACL facility name */ void aclErrorFmt(NSErr_t * errp, char * msgbuf, int maxlen, int maxdepth) { NSEFrame_t * efp; /* error frame pointer */ - int len; /* length of error message text */ + int len = 0; /* length of error message text */ int depth = 0; /* current depth */ msgbuf[0] = 0; diff --git a/lib/libaccess/acltools.cpp b/lib/libaccess/acltools.cpp index 9eb3292d..1b302df4 100644 --- a/lib/libaccess/acltools.cpp +++ b/lib/libaccess/acltools.cpp @@ -3060,7 +3060,7 @@ ACL_FileGetNameList(NSErr_t *errp, char * filename, char ***name_list) const int block_size = 50; int rv, list_size, list_index; - char ** local_list; + char ** local_list = NULL; char * block ; char * name; char * next; diff --git a/lib/libaccess/lasdns.cpp b/lib/libaccess/lasdns.cpp index 0b3d3dcf..de7d2a94 100644 --- a/lib/libaccess/lasdns.cpp +++ b/lib/libaccess/lasdns.cpp @@ -140,7 +140,7 @@ LASDnsBuild(NSErr_t *errp, char *attr_pattern, LASDnsContext_t *context, int ali size_t delimiter; /* length of valid token */ char token[256]; /* max length dns name */ int i; - int ipcnt; + int ipcnt = 0; char **p; unsigned long *ipaddrs=0; pool_handle_t *pool; @@ -347,7 +347,7 @@ int LASDnsEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator, int result; int aliasflg; char *my_dns; - LASDnsContext_t *context; + LASDnsContext_t *context = NULL; int rv; *cachable = ACL_INDEF_CACHABLE; diff --git a/lib/libaccess/lasip.cpp b/lib/libaccess/lasip.cpp index aa698de6..01c76aa6 100644 --- a/lib/libaccess/lasip.cpp +++ b/lib/libaccess/lasip.cpp @@ -340,7 +340,7 @@ LASIpAddPattern(NSErr_t *errp, int netmask, int pattern, LASIpTree_t **treetop) int stopbit; /* Don't care after this point */ int curbit; /* current bit we're working on */ int curval; /* value of pattern[curbit] */ - LASIpTree_t *curptr; /* pointer to the current node */ + LASIpTree_t *curptr = NULL; /* pointer to the current node */ LASIpTree_t *newptr; /* stop at the first 1 in the netmask from low to high */ @@ -448,7 +448,7 @@ int LASIpEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator, IPAddr_t ip; int retcode; LASIpTree_t *node; - LASIpContext_t *context; + LASIpContext_t *context = NULL; int rv; char ip_str[124]; diff --git a/lib/libaccess/ldapacl.cpp b/lib/libaccess/ldapacl.cpp index 6be89b18..4b7fdc8b 100644 --- a/lib/libaccess/ldapacl.cpp +++ b/lib/libaccess/ldapacl.cpp @@ -762,7 +762,7 @@ NSAPI_PUBLIC int acl_user_exists (const char *user, const char *userdn, PList_t resource = 0; PList_t auth_info = 0; PList_t global_auth = NULL; - int rv; + int rv = 0; /* Check if the userdn is available in the usr_cache */ if (acl_usr_cache_enabled() && userdn) { diff --git a/lib/libaccess/oneeval.cpp b/lib/libaccess/oneeval.cpp index a8f2b248..05de0e36 100644 --- a/lib/libaccess/oneeval.cpp +++ b/lib/libaccess/oneeval.cpp @@ -344,7 +344,7 @@ ACLEvalBuildContext( ACLHandle_t *acl; ACLExprHandle_t *ace; int ace_cnt = -1; - ACLAceEntry_t *acelast, *new_ace; + ACLAceEntry_t *acelast = NULL, *new_ace; ACLAceNumEntry_t *entry, *temp_entry; char **argp; ACLListCache_t *cache; @@ -635,7 +635,7 @@ ACL_INTEvalTestRights( int i, j, right_num, delta; ACLCachable_t ace_cachable; int result; - int absolute; + int absolute = 0; int skipflag; int g_num; /* index into the generic rights array. */ char **g_rights; diff --git a/lib/libsi18n/getstrmem.h b/lib/libsi18n/getstrmem.h index 12f58caf..cbdcbd17 100644 --- a/lib/libsi18n/getstrmem.h +++ b/lib/libsi18n/getstrmem.h @@ -53,7 +53,6 @@ static char emptyString[] = ""; #define NUM_BUCKETS 32 /* must be a power of 2 */ /* strings in library libadmin */ -static char* libadminid[] = {"$DBT: libadmin in memory v1 $"}; static char* libadmin[] = { "", " Help ", @@ -89,7 +88,6 @@ static struct DATABIN bucket5[] = { {emptyString,NULL,0} }; /* strings in library userforms */ -static char* userformsid[] = {"$DBT: userforms in memory v1 $"}; static char* userforms[] = { "", "Error: could not open servers list file.

\n", @@ -113,7 +111,6 @@ static struct DATABIN bucket8[] = { {emptyString,NULL,0} }; /* strings in library libaccess */ -static char* libaccessid[] = {"$DBT: libaccess in memory v1 $"}; static char* libaccess[] = { "", "basic-ncsa", @@ -274,7 +271,6 @@ static struct DATABIN bucket10[] = { {emptyString,NULL,0} }; /* strings in library frame */ -static char* frameid[] = {"$DBT: frame in memory v1 $"}; static char* frame[] = { "", "Not Found

Not Found

The requested object does not exist on this server. The link you followed is either outdated, inaccurate, or the server has been instructed not to let you have it. ", @@ -465,7 +461,6 @@ static struct DATABIN bucket17[] = { {emptyString,NULL,0} }; /* strings in library admserv */ -static char* admservid[] = {"$DBT: admserv in memory v1 $"}; static char* admserv[] = { "", "Unauthorized host", @@ -477,7 +472,6 @@ static char* admserv[] = { emptyString }; /* strings in library libir */ -static char* libirid[] = {"$DBT: libadmin in memory v1 $"}; static char* libir[] = { "", "An I/O error occurred before all form data could be read.", @@ -494,7 +488,6 @@ static struct DATABIN bucket19[] = { {emptyString,NULL,0} }; /* strings in library httpdaemon */ -static char* httpdaemonid[] = {"$DBT: httpdaemon in memory v1 $"}; static char* httpdaemon[] = { "", "Error in ConvertThreadToFiber", @@ -540,7 +533,6 @@ static struct DATABIN bucket20[] = { {emptyString,NULL,0} }; /* strings in library dsgw */ -static char* dsgwid[] = {"$DBT: dsgw in memory v1 $"}; static char* dsgw[] = { "", "Unknown HTTP request method", @@ -856,7 +848,6 @@ static struct DATABIN bucket26[] = { {emptyString,NULL,0} }; /* strings in library base */ -static char* baseid[] = {"$DBT: base in memory v1 $"}; static char* base[] = { "", "insufficient memory to create hash table", @@ -1072,7 +1063,6 @@ static struct DATABIN bucket27[] = { {emptyString,NULL,0} }; /* strings in library cgiadmin */ -static char* cgiadminid[] = {"$DBT: cgiadmin in memory v1 $"}; static char* cgiadmin[] = { "", "Missing REQUEST_METHOD", diff --git a/lib/libsi18n/gsslapd.h b/lib/libsi18n/gsslapd.h index ce77ed33..aad6ac20 100644 --- a/lib/libsi18n/gsslapd.h +++ b/lib/libsi18n/gsslapd.h @@ -54,10 +54,10 @@ #undef LIBRARY_NAME static RESOURCE_GLOBAL allxpstr[] = { - base, - libaccess, - libadmin, - 0 + {base}, + {libaccess}, + {libadmin}, + {0} }; #endif /* ifdef RESOURCE_STR */ -- cgit