bin/71628: [PATCH] cleanup of the usr.sbin/rpcbind code

Alfred Perlstein alfred at freebsd.org
Sun Sep 12 13:40:24 PDT 2004


The following reply was made to PR bin/71628; it has been noted by GNATS.

From: Alfred Perlstein <alfred at freebsd.org>
To: Giorgos Keramidas <keramida at freebsd.org>
Cc: Dan Lukes <dan at obluda.cz>, bug-followup at freebsd.org
Subject: Re: bin/71628: [PATCH] cleanup of the usr.sbin/rpcbind code
Date: Sun, 12 Sep 2004 13:35:50 -0700

 I'm having a hard time seeing these warnings, how are they
 being triggered?
 
 * Giorgos Keramidas <keramida at freebsd.org> [040912 13:07] wrote:
 > On 2004-09-12 04:38, Dan Lukes <dan at obluda.cz> wrote:
 > >   static int
 > >   init_transport(struct netconfig *nconf)
 > >   {
 > > - 	int fd;
 > > + 	int fd = fd;  /* init to suppres "may be used uninitialized" warning */
 > 
 > Err, no please.  GCC complains that fd "may be used uninitialized" because
 > of this construct near line 275 and the rest of the function body:
 > 
 >     275         if (nconf->nc_semantics != NC_TPI_CLTS) {
 >     276                 if ((fd = __rpc_nconf2fd(nconf)) < 0) {
 >     277                         int non_fatal = 0;
 >     ...
 >     283                         return (1);
 >     284                 }
 >     ...
 >     311         if (nconf->nc_semantics == NC_TPI_CLTS) {
 >     ...
 >     334                 while (nhostsbak > 0) {
 >     ...
 >     339                         if ((fd = __rpc_nconf2fd(nconf)) < 0) {
 >     ...
 >     452         } else {
 >     ...
 >     466                 if (bind(fd, sa, addrlen) < 0) {
 > 
 > Pay attention to this last line.  GCC believes that fd can be used
 > uninitialized because if NC_TPI_CLTS is not used the bind() call will
 > receive an uninitialized value of `fd'.  I'm not acquainted with the
 > internals of rpcbind() at all, but I know that Alfred Perlstein is.
 > He's probably the best person to suggest a fix for this warning, if one
 > is really needed.
 > 
 > >   	struct t_bind taddr;
 > >   	struct addrinfo hints, *res = NULL;
 > >   	struct __rpc_sockinfo si;
 > > - 	SVCXPRT	*my_xprt;
 > > ! 	SVCXPRT	*my_xprt = my_xprt; /* init to suppres "may be used uninitialized" warning */
 > 
 > No.  I don't know why you think that this is a good fix for all the
 > uninitialized pointer warnings.  It's not.  Never :-/
 > 
 > This warning is probably caused by GCC's inability to make sure that when
 > `bar' is a pointer this construct is perfectly fine:
 > 
 > 	if (foo) {
 > 		...
 > 		if (bar = baz())
 > 			...
 > 	} else {
 > 		...
 > 		if (bar = baz2())
 > 			...
 > 	}
 > 
 > 	if (blah(bar))
 > 		...
 > 
 > After a quick glance at the source of rpcbind() I think that there's no way
 > that my_xrpt can be used uninitialized.  A proper fix for this warning
 > would be then to just set my_xrpt to NULL at first and let the rest of the
 > function unchanged regarding my_xrpt.
 
 -- 
 - Alfred Perlstein
 - Research Engineering Development Inc.
 - email: bright at mu.org cell: 408-480-4684


More information about the freebsd-bugs mailing list