svn commit: r226153 - head/usr.bin/kdump

Bruce Evans brde at optusnet.com.au
Sat Oct 8 16:10:39 UTC 2011


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


More information about the svn-src-head mailing list