Advent4 patch, second try

Stefan Sperling stsp at
Wed Sep 26 17:56:41 CEST 2007

On Wed, Sep 26, 2007 at 05:22:50PM +0200, Luis Javier Merino wrote:
>  		exit(0);
> -	if (sptr = strchr(username, '\n'))
> +	if (sptr == strchr(username, '\n'))
>  		*sptr = '\0';
> It is customary to assign values to a variable inside an if condition
> if you intend to reuse the result of a function.

And it's lazy and stupid not to test the condition explicitely.
Something like:

	if ((sptr = strchr(username, '\n')) != NULL)

is easier to understand for humans and the same to the compiler.

Or simply avoid assigning inside a conditional statement altogether.
Even if just not to confuse newbies reading the code.

If you need to know tons of crazy idioms to read code,
it's not well written. This attiude leads to brain-damaged
stuff like using

	*((char *) mempcpy (dst, src, n)) = '\0';

to copy a string.


> Aside from that, I wouldn't really lose time fixing warnings on  code
> written for pre-ANSI compilers.

True, but at the same time these warnings are quite annoying.

stefan                                         PGP Key: 0xF59D25F0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : 

More information about the dslinux-devel mailing list