iproute2: fix several warnings emitted by clang scan-build
Subsystems (2)
PATCH 1/1 iproute2: fix several warnings emitted by clang scan-build
* genl/genl.c: remove unused basename logic, avoid dereference of possibly NULL variable
* ip/iptuntap.c: avoid double open and leak of file handle
* misc/arpd.c: zero out socklen structure
* misc/{ifstat,nstat,rtacct}.c: ensure uptime is initialized if /proc/uptime cannot be opened
* tc/m_xt.c: only unset fields if m is non-NULL
--- genl/genl.c | 11 ++--------- ip/iptuntap.c | 2 +- misc/arpd.c | 2 ++ misc/ifstat.c | 2 +- misc/nstat.c | 2 +- misc/rtacct.c | 2 +- tc/m_xt.c | 15 ++++++++------- 7 files changed, 16 insertions(+), 20 deletions(-)
genl/genl.c +2 -9
@@ -109,14 +109,6 @@ static void usage(void)int main (int argc,char **argv) { -char *basename; - - basename =strrchr (argv[0 ],'/' ); -if (basename ==NULL ) - basename = argv[0 ]; -else - basename++; -while (argc >1 ) {if (argv[1 ][0 ] !='-' )break ;
@@ -144,8 +136,9 @@ int main(int argc, char **argv)int ret;struct genl_util *a =NULL ; a =get_genl_kind (argv[1 ]); -if (NULL == a) { +if (!a) {fprintf (stderr,"bad genl %s\n" ,argv[1 ]); +exit (-1 ); } ret = a->parse_genlopt (a, argc-1 , argv+1 );
ip/iptuntap.c +1 -1
@@ -47,7 +47,7 @@ static void usage(void)static int tap_add_ioctl (struct ifreq *ifr,uid_t uid,gid_t gid) { -int fd =open (TUNDEV ,O_RDWR ); +int fd;int ret =-1 ;#ifdef IFF_TUN_EXCL
misc/arpd.c +2 -0
@@ -485,6 +485,8 @@ void get_arp_pkt(void)DBT dbkey, dbdat;int n; +memset (&sll,0 ,sizeof (sll)); + n =recvfrom (pset[0 ].fd, buf,sizeof (buf),MSG_DONTWAIT , (struct sockaddr *)&sll, &sll_len);if (n <0 ) {
misc/ifstat.c +1 -1
@@ -708,7 +708,7 @@ int main(int argc, char *argv[]) }if (!ignore_history) {FILE *tfp; -long uptime; +long uptime =-1 ;if ((tfp =fopen ("/proc/uptime" ,"r" )) !=NULL ) {if (fscanf (tfp,"%ld" , &uptime) !=1 ) uptime =-1 ;
misc/nstat.c +1 -1
@@ -560,7 +560,7 @@ int main(int argc, char *argv[]) }if (!ignore_history) {FILE *tfp; -long uptime; +long uptime =-1 ;if ((tfp =fopen ("/proc/uptime" ,"r" )) !=NULL ) {if (fscanf (tfp,"%ld" , &uptime) !=1 ) uptime =-1 ;
misc/rtacct.c +1 -1
@@ -580,7 +580,7 @@ int main(int argc, char *argv[])if (!ignore_history) {FILE *tfp; -long uptime; +long uptime =-1 ;if ((tfp =fopen ("/proc/uptime" ,"r" )) !=NULL ) {if (fscanf (tfp,"%ld" , &uptime) !=1 ) uptime =-1 ;
tc/m_xt.c +8 -7
@@ -252,13 +252,14 @@ static int parse_ipt(struct action_util *a,int *argc_p, optind =0 ;xtables_free_opts (1 ); -/* Clear flags if target will be used again */ - m->tflags=0 ; - m->used=0 ; -/* Free allocated memory */ -if (m->t) -free (m->t); - +if (m) { +/* Clear flags if target will be used again */ + m->tflags =0 ; + m->used =0 ; +/* Free allocated memory */ +if (m->t) +free (m->t); + }return 0 ;
Signature · 1 line
1.7.6
Quoted 9 lines · On Fri, 15 Jul 2011 14:59:26 -0500 Dan McGee <[email protected]> wrote:
*
genl/genl.c: remove unused basename logic, avoid dereference of possibly NULL variable
*ip/iptuntap.c: avoid double open and leak of file handle
*misc/arpd.c: zero out socklen structure
*misc/{ifstat,nstat,rtacct}.c: ensure uptime is initialized if/proc/uptimecannot be opened
*tc/m_xt.c: only unset fields if m is non-NULLSigned-off-by Dan McGee <[email protected]>
All but arpd applied. The arpd change is unnecessary since the socket structure is in recvfrom() call it will be set by kernel.