nfs-utils compiler warning clean ups
Subsystems (2)
cover nfs-utils compiler warning clean ups
Hi-
These address compiler warnings in mountd and gssd that I've found during recent sojourns in that code base. I've done some light testing, but more critical review and testing would be appreciated.
I think these are appropriate for your next release of nfs-utils.
---
Chuck Lever (10):
rpc.gssd: Squelch compiler error
rpc.gssd: Squelch compiler warning
rpc.gssd: Squelch compiler warning
mountd: Avoid unnecessary type conversions
mountd: Avoid unnecessary type conversions
mountd: Avoid unnecessary type conversions
mountd: Make local functions static
mountd: Eliminate unnecessary type conversions
mountd: Avoid unnecessary type conversions
nfs-utils: Eliminate dereferencing type punned pointers
support/include/nfslib.h | 1 + support/include/sockaddr.h | 10 ++++------ support/nfs/cacheio.c | 5 +++++ utils/gssd/gss_util.c | 2 +- utils/gssd/gssd_proc.c | 13 +++++++------ utils/mountd/cache.c | 34 ++++++++++++++++++---------------- 6 files changed, 36 insertions(+), 29 deletions(-)
Signature · 1 line
Chuck Lever
PATCH 1/10 nfs-utils: Eliminate dereferencing type punned pointers
Clean up compiler warnings:
../../support/include/sockaddr.h: In function ‘compare_sockaddr6’:../../support/include/sockaddr.h:197:2: warning: dereferencing
type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]../../support/include/sockaddr.h:198:7: warning: dereferencing
type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]../../support/include/sockaddr.h:199:6: warning: dereferencing
type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]../../support/include/sockaddr.h:200:7: warning: dereferencing
type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]../../support/include/sockaddr.h:204:2: warning: dereferencing
type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]../../support/include/sockaddr.h:204:2: warning: dereferencing
type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]../../support/include/sockaddr.h:204:2: warning: dereferencing
type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]../../support/include/sockaddr.h:204:2: warning: dereferencing
type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]../../support/include/sockaddr.h:204:2: warning: dereferencing
type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]../../support/include/sockaddr.h:204:2: warning: dereferencing
type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]../../support/include/sockaddr.h:204:2: warning: dereferencing
type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]../../support/include/sockaddr.h:204:2: warning: dereferencing
type-punned pointer might break strict-aliasing rules [-Wstrict-aliasing]
Seen with gcc version 4.6.3 20120306 (Red Hat 4.6.3-2) (GCC)
Note also that site-local IPv6 addresses are deprecated, and thus are no longer encountered.
---
support/include/sockaddr.h | 10 ++++------ 1 files changed, 4 insertions(+), 6 deletions(-)
support/include/sockaddr.h +4 -6
@@ -193,16 +193,14 @@ compare_sockaddr6(const struct sockaddr *sa1, const struct sockaddr *sa2) {const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sa1;const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sa2; +const struct in6_addr *saddr1 = &sin1->sin6_addr; +const struct in6_addr *saddr2 = &sin2->sin6_addr; -if ((IN6_IS_ADDR_LINKLOCAL ((char *)&sin1->sin6_addr) && -IN6_IS_ADDR_LINKLOCAL ((char *)&sin2->sin6_addr)) || - (IN6_IS_ADDR_SITELOCAL ((char *)&sin1->sin6_addr) && -IN6_IS_ADDR_SITELOCAL ((char *)&sin2->sin6_addr))) +if (IN6_IS_ADDR_LINKLOCAL (saddr1) &&IN6_IS_ADDR_LINKLOCAL (saddr2))if (sin1->sin6_scope_id != sin2->sin6_scope_id)return false; -return IN6_ARE_ADDR_EQUAL ((char *)&sin1->sin6_addr, - (char *)&sin2->sin6_addr); +return IN6_ARE_ADDR_EQUAL (saddr1, saddr2); }#else /* !IPV6_SUPPORTED */ static inline _Bool
PATCH 2/10 mountd: Avoid unnecessary type conversions
In reply to Chuck LeverClean up compiler warnings:
cache.c: In function ‘auth_unix_ip’:
cache.c:121:29: warning: conversion to ‘unsigned int’ from ‘time_t’
may alter its value [-Wconversion]
cache.c: In function ‘auth_unix_gid’:
cache.c:186:29: warning: conversion to ‘unsigned int’ from ‘time_t’
may alter its value [-Wconversion]
cache.c: In function ‘dump_to_cache’:
cache.c:733:30: warning: conversion to ‘unsigned int’ from ‘time_t’
may alter its value [-Wconversion]
cache.c:753:30: warning: conversion to ‘unsigned int’ from ‘time_t’
may alter its value [-Wconversion]
cache.c: In function ‘cache_export’:
cache.c:1324:29: warning: conversion to ‘unsigned int’ from ‘time_t’
may alter its value [-Wconversion]
Seen with gcc version 4.6.3 20120306 (Red Hat 4.6.3-2) (GCC)
We can take the opportunity to eliminate some code duplication.
---
support/include/nfslib.h | 1 + support/nfs/cacheio.c | 5 +++++ utils/mountd/cache.c | 10 +++++----- 3 files changed, 11 insertions(+), 5 deletions(-)
support/include/nfslib.h +1 -0
@@ -164,6 +164,7 @@ void qword_adduint(char **bpp, int *lp, unsigned int n);void qword_addeol (char **bpp,int *lp);int qword_get_uint (char **bpp,unsigned int *anint);void qword_printuint (FILE *f,unsigned int num); +void qword_printtimefrom (FILE *f,unsigned int num);void closeall (int min);
support/nfs/cacheio.c +5 -0
@@ -153,6 +153,11 @@ void qword_printuint(FILE *f, unsigned int num)fprintf (f,"%u " , num); } +void qword_printtimefrom (FILE *f,unsigned int num) +{ +fprintf (f,"%lu " ,time (0 ) + num); +} +int qword_eol (FILE *f) {int err;
utils/mountd/cache.c +5 -5
@@ -118,7 +118,7 @@ static void auth_unix_ip(FILE *f) }qword_print (f,"nfsd" );qword_print (f, ipaddr); -qword_printuint (f,time (0 ) +DEFAULT_TTL ); +qword_printtimefrom (f,DEFAULT_TTL );if (use_ipaddr)qword_print (f, ipaddr);else if (client)
@@ -183,7 +183,7 @@ static void auth_unix_gid(FILE *f) } }qword_printuint (f, uid); -qword_printuint (f,time (0 ) +DEFAULT_TTL ); +qword_printtimefrom (f,DEFAULT_TTL );if (rv >=0 ) {qword_printuint (f, ngroups);for (i=0 ; i<ngroups; i++)
@@ -730,7 +730,7 @@ static int dump_to_cache(FILE *f, char *domain, char *path, struct exportent *exint different_fs =strcmp (path, exp->e_path) !=0 ;int flag_mask = different_fs ? ~NFSEXP_FSID : ~0 ; -qword_printuint (f,time (0 ) + exp->e_ttl); +qword_printtimefrom (f, exp->e_ttl);qword_printint (f, exp->e_flags & flag_mask);qword_printint (f, exp->e_anonuid);qword_printint (f, exp->e_anongid);
@@ -750,7 +750,7 @@ static int dump_to_cache(FILE *f, char *domain, char *path, struct exportent *exqword_printhex (f, u,16 ); } }else -qword_printuint (f,time (0 ) +DEFAULT_TTL ); +qword_printtimefrom (f,DEFAULT_TTL );return qword_eol (f); }
@@ -1339,7 +1339,7 @@ int cache_export(nfs_export *exp, char *path)qword_print (f,"nfsd" );qword_print (f,host_ntop (get_addrlist (exp->m_client,0 ), buf,sizeof (buf))); -qword_printuint (f,time (0 ) + exp->m_export.e_ttl); +qword_printtimefrom (f, exp->m_export.e_ttl);qword_print (f, exp->m_client->m_hostname); err =qword_eol (f);
PATCH 3/10 mountd: Eliminate unnecessary type conversions
In reply to Chuck LeverClean up compiler warnings:
cache.c:332:16: warning: conversion to ‘int’ from ‘size_t’ may alter
its value [-Wconversion]
cache.c:339:9: warning: conversion to ‘size_t’ from ‘int’ may change
the sign of the result [-Wsign-conversion]cache.c: In function ‘subexport’:
cache.c:354:17: warning: conversion to ‘int’ from ‘size_t’ may alter
its value [-Wconversion]
cache.c:357:9: warning: conversion to ‘size_t’ from ‘int’ may change
the sign of the result [-Wsign-conversion]
Seen with gcc version 4.6.3 20120306 (Red Hat 4.6.3-2) (GCC) .
---
utils/mountd/cache.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
utils/mountd/cache.c +2 -2
@@ -329,7 +329,7 @@ static char *next_mnt(void **v, char *p) {FILE *f;struct mntent *me; -int l =strlen (p); +size_t l =strlen (p);if (*v ==NULL ) { f =setmntent ("/etc/mtab" ,"r" ); *v = f;
@@ -351,7 +351,7 @@ static char *next_mnt(void **v, char *p)static bool subexport (struct exportent *e1,struct exportent *e2) {char *p1 = e1->e_path, *p2 = e2->e_path; -int l2 =strlen (p2); +size_t l2 =strlen (p2);return e2->e_flags &NFSEXP_CROSSMOUNT &&strncmp (p1, p2, l2) ==0
PATCH 4/10 mountd: Make local functions static
In reply to Chuck LeverClean up compiler warnings:
cache.c: At top level:
cache.c:373:5: warning: no previous prototype for ‘parse_fsid’
[-Wmissing-prototypes]
cache.c: At top level:
cache.c:504:18: warning: no previous prototype for
‘lookup_client_addr’ [-Wmissing-prototypes]
Seen with gcc version 4.6.3 20120306 (Red Hat 4.6.3-2) (GCC)
Once the parse_fsid() function was made static, the compiler detected execution paths through it that did not initialize some fields in *parsed.
[ I'm pretty sure these problems are currently harmless, since each path is taken depending on the value of the .fsidtype field. Each path accesses only the fields in *parsed that it cares about. ]
cache.c: In function ‘nfsd_fh’:
cache.c:500:13: warning: ‘parsed.fhuuid’ may be used uninitialized
in this function [-Wuninitialized]
cache.c:535:21: note: ‘parsed.fhuuid’ was declared here cache.c:495:21: warning: ‘parsed.uuidlen’ may be used uninitialized
in this function [-Wuninitialized]
cache.c:535:21: note: ‘parsed.uuidlen’ was declared here cache.c:477:46: warning: ‘*((void *)&parsed+16)’ may be used
uninitialized in this function [-Wuninitialized]
cache.c:535:21: note: ‘*((void *)&parsed+16)’ was declared here cache.c:472:51: warning: ‘parsed.minor’ may be used uninitialized
in this function [-Wuninitialized]
cache.c:535:21: note: ‘parsed.minor’ was declared here cache.c:472:6: warning: ‘parsed.major’ may be used uninitialized
in this function [-Wuninitialized]
cache.c:535:21: note: ‘parsed.major’ was declared here cache.c:483:18: warning: ‘*((void *)&parsed+4)’ may be used
uninitialized in this function [-Wuninitialized]
cache.c:535:21: note: ‘*((void *)&parsed+4)’ was declared here
This is because parsed_fsid isn't a union type. parse_fsid() leaves uninitialized fields that are not used by a particular fsidtype. To prevent an accidental dereference of stack garbage (.fhuuid being an example of a pointer that is left uninitialized sometimes), have parse_fsid() defensively pre-initialize *parsed to zero.
---
utils/mountd/cache.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
utils/mountd/cache.c +4 -2
@@ -370,11 +370,13 @@ struct parsed_fsid {char *fhuuid; }; -int parse_fsid (int fsidtype,int fsidlen,char *fsid,struct parsed_fsid *parsed) +static int parse_fsid (int fsidtype,int fsidlen,char *fsid, +struct parsed_fsid *parsed) {unsigned int dev;unsigned long long inode64; +memset (parsed,0 ,sizeof (*parsed)); parsed->fsidtype = fsidtype;switch (fsidtype) {case FSID_DEV :/* 4 bytes: 2 major, 2 minor, 4 inode */
@@ -501,7 +503,7 @@ static bool match_fsid(struct parsed_fsid *parsed, nfs_export *exp, char *path)return false; } -struct addrinfo *lookup_client_addr (char *dom) +static struct addrinfo *lookup_client_addr (char *dom) {struct addrinfo *ret;struct addrinfo *tmp;
PATCH 5/10 mountd: Avoid unnecessary type conversions
In reply to Chuck LeverClean up compiler warnings:
cache.c: In function ‘get_uuid’:
cache.c:249:2: warning: conversion to ‘size_t’ from ‘int’ may change
the sign of the result [-Wsign-conversion]
And the like.
Seen with gcc version 4.6.3 20120306 (Red Hat 4.6.3-2) (GCC)
---
utils/mountd/cache.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
utils/mountd/cache.c +4 -4
@@ -238,13 +238,13 @@ static const char *get_uuid_blkdev(char *path)#define get_uuid_blkdev (path) (NULL)#endif -static int get_uuid (const char *val,int uuidlen,char *u) +static int get_uuid (const char *val,size_t uuidlen,char *u) {/* extract hex digits from uuidstr and compose a uuid * of the given length (max 16), xoring bytes to make * a smaller uuid. */ -int i =0 ; +size_t i =0 ;memset (u,0 , uuidlen);for ( ; *val ; val++) {
@@ -268,7 +268,7 @@ static int get_uuid(const char *val, int uuidlen, char *u)return 1 ; } -static int uuid_by_path (char *path,int type,int uuidlen,char *uuid) +static int uuid_by_path (char *path,int type,size_t uuidlen,char *uuid) {/* get a uuid for the filesystem found at 'path'. * There are several possible ways of generating the
@@ -366,7 +366,7 @@ struct parsed_fsid {unsigned int minor;unsigned int major;unsigned int fsidnum; -int uuidlen; +size_t uuidlen;char *fhuuid; };
PATCH 6/10 mountd: Avoid unnecessary type conversions
In reply to Chuck LeverClean up compiler warnings:
cache.c: In function ‘is_subdirectory’:
cache.c:760:16: warning: conversion to ‘int’ from ‘size_t’ may
alter its value [-Wconversion]
cache.c:763:3: warning: conversion to ‘size_t’ from ‘int’ may
change the sign of the result [-Wsign-conversion]
---
utils/mountd/cache.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
utils/mountd/cache.c +1 -1
@@ -758,7 +758,7 @@ static int dump_to_cache(FILE *f, char *domain, char *path, struct exportent *exstatic int is_subdirectory (char *child,char *parent) { -int l =strlen (parent); +size_t l =strlen (parent);return strcmp (child, parent) ==0 || (strncmp (child, parent, l) ==0 && child[l] =='/' );
PATCH 7/10 mountd: Avoid unnecessary type conversions
In reply to Chuck LeverClean up compiler warnings:
cache.c: In function ‘get_uuid’:
cache.c:256:17: warning: conversion to ‘char’ from ‘int’ may
alter its value [-Wconversion]
cache.c:258:17: warning: conversion to ‘char’ from ‘int’ may
alter its value [-Wconversion]
cache.c:260:16: warning: conversion to ‘char’ from ‘int’ may
alter its value [-Wconversion]
cache.c:262:6: warning: conversion to ‘char’ from ‘int’ may
alter its value [-Wconversion]
Seen with gcc version 4.6.3 20120306 (Red Hat 4.6.3-2) (GCC)
---
utils/mountd/cache.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
utils/mountd/cache.c +2 -2
@@ -248,7 +248,7 @@ static int get_uuid(const char *val, size_t uuidlen, char *u)memset (u,0 , uuidlen);for ( ; *val ; val++) { -char c = *val; +int c = *val;if (!isxdigit (c))continue ;if (isalpha (c)) {
@@ -260,7 +260,7 @@ static int get_uuid(const char *val, size_t uuidlen, char *u) c = c -'0' +0 ;if ((i&1 ) ==0 ) c <<=4 ; - u[i/2 ] ^= c; + u[i/2 ] ^= (char )c; i++;if (i == uuidlen*2 ) i =0 ;
PATCH 8/10 rpc.gssd: Squelch compiler warning
In reply to Chuck Levergss_util.c: At top level:
gss_util.c:98:36: warning: ISO C does not allow extra ‘;’ outside of a function [-pedantic]
---
utils/gssd/gss_util.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
utils/gssd/gss_util.c +1 -1
@@ -95,7 +95,7 @@/* Global gssd_credentials handle */ gss_cred_id_t gssd_creds; -gss_OID g_mechOid =GSS_C_NULL_OID ;; +gss_OID g_mechOid =GSS_C_NULL_OID ;#if 0 static void
PATCH 9/10 rpc.gssd: Squelch compiler warning
In reply to Chuck Levergssd_proc.c: At top level:
gssd_proc.c:782:5: warning: no previous prototype for ‘create_auth_rpc_client’ [-Wmissing-prototypes]
---
utils/gssd/gssd_proc.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
utils/gssd/gssd_proc.c +6 -5
@@ -802,11 +802,12 @@ set_port:* Create an RPC connection and establish an authenticated * gss context with a server. */ -int create_auth_rpc_client (struct clnt_info *clp, -CLIENT **clnt_return, -AUTH **auth_return, -uid_t uid, -int authtype) +static int +create_auth_rpc_client (struct clnt_info *clp, +CLIENT **clnt_return, +AUTH **auth_return, +uid_t uid, +int authtype) {CLIENT *rpc_clnt =NULL ;struct rpc_gss_sec sec;
PATCH 10/10 rpc.gssd: Squelch compiler error
In reply to Chuck Levergssd_proc.c: In function ‘handle_krb5_upcall’:
gssd_proc.c:1117:2: warning: ISO C forbids ‘return’ with expression, in function returning void [-pedantic]
---
utils/gssd/gssd_proc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
utils/gssd/gssd_proc.c +1 -1
@@ -1116,7 +1116,7 @@ handle_krb5_upcall(struct clnt_info *clp)return ; } -return process_krb5_upcall (clp, uid, clp->krb5_fd,NULL ,NULL ); +process_krb5_upcall (clp, uid, clp->krb5_fd,NULL ,NULL ); }void
Quoted 7 lines · Chuck Lever
Hi-
These address compiler warnings in mountd and gssd that I've found during recent sojourns in that code base. I've done some light testing, but more critical review and testing would be appreciated.
I think these are appropriate for your next release of nfs-utils.
What CFLAGS do you use to see these warnings? Every time I do a build I check for warnings and if I would have seen these I would have fixed them immediately...
BTW, I'm using gcc version 4.7.2 20120921 (Red Hat 4.7.2-2) (GCC) to do my builds these days...
steved.
Quoted 24 lines
---
Chuck Lever (10):
rpc.gssd: Squelch compiler error
rpc.gssd: Squelch compiler warning
rpc.gssd: Squelch compiler warning
mountd: Avoid unnecessary type conversions
mountd: Avoid unnecessary type conversions
mountd: Avoid unnecessary type conversions
mountd: Make local functions static
mountd: Eliminate unnecessary type conversions
mountd: Avoid unnecessary type conversions
nfs-utils: Eliminate dereferencing type punned pointerssupport/include/nfslib.h | 1 + support/include/sockaddr.h | 10 ++++------ support/nfs/cacheio.c | 5 +++++ utils/gssd/gss_util.c | 2 +- utils/gssd/gssd_proc.c | 13 +++++++------ utils/mountd/cache.c | 34 ++++++++++++++++++---------------- 6 files changed, 36 insertions(+), 29 deletions(-)
The compiler flag that enables a warning is listed in square brackets at the end of each warning message. Like: [-wsigned-comparison]
Sent from my iPhone
Quoted 43 lines · Steve Dickson
Quoted 7 lines · Chuck Lever
Hi-
These address compiler warnings in mountd and gssd that I've found during recent sojourns in that code base. I've done some light testing, but more critical review and testing would be appreciated.
I think these are appropriate for your next release of nfs-utils.
What CFLAGS do you use to see these warnings? Every time I do a build I check for warnings and if I would have seen these I would have fixed them immediately...
BTW, I'm using gcc version 4.7.2 20120921 (Red Hat 4.7.2-2) (GCC) to do my builds these days...
steved.
Quoted 24 lines
---
Chuck Lever (10):
rpc.gssd: Squelch compiler error
rpc.gssd: Squelch compiler warning
rpc.gssd: Squelch compiler warning
mountd: Avoid unnecessary type conversions
mountd: Avoid unnecessary type conversions
mountd: Avoid unnecessary type conversions
mountd: Make local functions static
mountd: Eliminate unnecessary type conversions
mountd: Avoid unnecessary type conversions
nfs-utils: Eliminate dereferencing type punned pointerssupport/include/nfslib.h | 1 + support/include/sockaddr.h | 10 ++++------ support/nfs/cacheio.c | 5 +++++ utils/gssd/gss_util.c | 2 +- utils/gssd/gssd_proc.c | 13 +++++++------ utils/mountd/cache.c | 34 ++++++++++++++++++---------------- 6 files changed, 36 insertions(+), 29 deletions(-)
Quoted 23 lines · Chuck Lever
Hi-
These address compiler warnings in mountd and gssd that I've found during recent sojourns in that code base. I've done some light testing, but more critical review and testing would be appreciated.
I think these are appropriate for your next release of nfs-utils.
---
Chuck Lever (10):
rpc.gssd: Squelch compiler error
rpc.gssd: Squelch compiler warning
rpc.gssd: Squelch compiler warning
mountd: Avoid unnecessary type conversions
mountd: Avoid unnecessary type conversions
mountd: Avoid unnecessary type conversions
mountd: Make local functions static
mountd: Eliminate unnecessary type conversions
mountd: Avoid unnecessary type conversions
nfs-utils: Eliminate dereferencing type punned pointers
Quoted 8 lines
support/include/nfslib.h | 1 + support/include/sockaddr.h | 10 ++++------ support/nfs/cacheio.c | 5 +++++ utils/gssd/gss_util.c | 2 +- utils/gssd/gssd_proc.c | 13 +++++++------ utils/mountd/cache.c | 34 ++++++++++++++++++---------------- 6 files changed, 36 insertions(+), 29 deletions(-)
All 10 patches have been committed...
steved.