mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Harvey Harrison <harvey.harrison@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/5] isdn: fix integer as NULL pointer warning
Date: Fri, 23 May 2008 08:08:57 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.1.10.0805230803290.3081@woody.linux-foundation.org> (raw)
In-Reply-To: <1211496307.6888.10.camel@brick>



On Thu, 22 May 2008, Harvey Harrison wrote:
>  	len += sprintf(page+len, "%-16s %s\n", "type", s);
> -	if ((s = cinfo->version[VER_DRIVER]) != 0)
> +	if ((s = cinfo->version[VER_DRIVER]) != NULL)
>  		len += sprintf(page+len, "%-16s %s\n", "ver_driver", s);

For thigns like this (ie testing an assignment), I personally much prefer

	s = cinfo->version[VER_DRIVER];
	if (s)
		len += sprintf(page+len, "%-16s %s\n", "ver_driver", s);

over the uglier and unreadable version.

IOW, testing assignments is good only when:

 - you have to do it because of syntax (ie notably in a "while()" loop)

 - there's some reason you want it to be a single statement (eg doing a 
   macro or other thing)

 - of the assignment is really simple, and the test is not against NULL or 
   zero.

The reason for that "the test is not against NULL or zero" is that testing 
for NULL and 0 is better done with just a "if (x)", and in an assignment 
that just means either (a) a incomprehensible extra parenthesis just to 
shut the compiler up or (b) changing the simple test into a stupid test 
(ie doing "if (x != NULL)").

(b) is much preferable to (a), but just doing it as two statements is 
much preferable to either!

		Linus

      reply	other threads:[~2008-05-23 15:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-22 22:45 Harvey Harrison
2008-05-23 15:08 ` Linus Torvalds [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.1.10.0805230803290.3081@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=harvey.harrison@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®