Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Oct 2011 03:10:35 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Dag-Erling Smorgrav <des@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r226153 - head/usr.bin/kdump
Message-ID:  <20111009030101.Q1307@besplex.bde.org>
In-Reply-To: <201110081228.p98CS70F062542@svn.freebsd.org>
References:  <201110081228.p98CS70F062542@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 8 Oct 2011, Dag-Erling Smorgrav wrote:

> Log:
>  I appreciate the logic behind using a (void) cast to indicate that the
>  return value is intentionally ignored, but frankly, all it does is
>  get in the way of the code.

It would be more useful if used precisely when ignoring the return
value is correct (and unusual -- never use it for printf()).  For
example, when printf() is voided, there must be an fflush() and error
checking of that at least once in the program (much more often for
interactive programs), but most programs that void printf() don't
bother with that.  kdump was one.  It has a single fflush() at the end
of main() (which is a reasonable place to put it for simple programs),
but only for the -l case, and with null error checking:

> Modified: head/usr.bin/kdump/kdump.c
> ==============================================================================
> --- head/usr.bin/kdump/kdump.c	Sat Oct  8 12:27:12 2011	(r226152)
> +++ head/usr.bin/kdump/kdump.c	Sat Oct  8 12:28:06 2011	(r226153)
> @@ -307,7 +307,7 @@ main(int argc, char *argv[])
> 			break;
> 		}
> 		if (tail)
> -			(void)fflush(stdout);
> +			fflush(stdout);
> 	}
> 	return 0;
> }

Voiding the result of fflush() is just a bug, unless there is an ferror()
check, which there isn't.  Now this code correctly doesn't claim that
ignoring the result is correct.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20111009030101.Q1307>