public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add spaces on either side of case "..." operator.
@ 2007-04-10 11:23 Robert P. J. Day
  2007-04-10 14:33 ` WANG Cong
  2007-04-10 16:05 ` Andrew Morton
  0 siblings, 2 replies; 6+ messages in thread
From: Robert P. J. Day @ 2007-04-10 11:23 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: Andrew Morton


Following the programming advice laid down in the gcc manual, make
sure the case "..." operator has spaces on either side.

Signed-off-by: Robert P. J. Day <rpjday@mindspring.com>

---

According to:

http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Case-Ranges.html#Case-Ranges:

  "Be careful: Write spaces around the ..., for otherwise it may be
parsed wrong when you use it with integer values."


diff --git a/kernel/audit.c b/kernel/audit.c
index 76c9a11..d963a04 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -515,8 +515,8 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)
 			err = -EPERM;
 		break;
 	case AUDIT_USER:
-	case AUDIT_FIRST_USER_MSG...AUDIT_LAST_USER_MSG:
-	case AUDIT_FIRST_USER_MSG2...AUDIT_LAST_USER_MSG2:
+	case AUDIT_FIRST_USER_MSG ... AUDIT_LAST_USER_MSG:
+	case AUDIT_FIRST_USER_MSG2 ... AUDIT_LAST_USER_MSG2:
 		if (security_netlink_recv(skb, CAP_AUDIT_WRITE))
 			err = -EPERM;
 		break;
@@ -614,8 +614,8 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 							loginuid, sid);
 		break;
 	case AUDIT_USER:
-	case AUDIT_FIRST_USER_MSG...AUDIT_LAST_USER_MSG:
-	case AUDIT_FIRST_USER_MSG2...AUDIT_LAST_USER_MSG2:
+	case AUDIT_FIRST_USER_MSG ... AUDIT_LAST_USER_MSG:
+	case AUDIT_FIRST_USER_MSG2 ... AUDIT_LAST_USER_MSG2:
 		if (!audit_enabled && msg_type != AUDIT_USER_AVC)
 			return 0;

-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://fsdev.net/wiki/index.php?title=Main_Page
========================================================================

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Add spaces on either side of case "..." operator.
  2007-04-10 11:23 [PATCH] Add spaces on either side of case "..." operator Robert P. J. Day
@ 2007-04-10 14:33 ` WANG Cong
  2007-04-10 16:05 ` Andrew Morton
  1 sibling, 0 replies; 6+ messages in thread
From: WANG Cong @ 2007-04-10 14:33 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: Linux Kernel Mailing List, Andrew Morton

On Tue, Apr 10, 2007 at 07:23:35AM -0400, Robert P. J. Day wrote:
>
>Following the programming advice laid down in the gcc manual, make
>sure the case "..." operator has spaces on either side.
>
>Signed-off-by: Robert P. J. Day <rpjday@mindspring.com>
>

Acked-by: WANG Cong <xiyou.wangcong@gmail.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Add spaces on either side of case "..." operator.
  2007-04-10 11:23 [PATCH] Add spaces on either side of case "..." operator Robert P. J. Day
  2007-04-10 14:33 ` WANG Cong
@ 2007-04-10 16:05 ` Andrew Morton
  2007-04-10 17:47   ` Jeremy Fitzhardinge
  2007-04-10 20:37   ` Alexey Dobriyan
  1 sibling, 2 replies; 6+ messages in thread
From: Andrew Morton @ 2007-04-10 16:05 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: Linux Kernel Mailing List

On Tue, 10 Apr 2007 07:23:35 -0400 (EDT) "Robert P. J. Day" <rpjday@mindspring.com> wrote:

> Following the programming advice laid down in the gcc manual, make
> sure the case "..." operator has spaces on either side.
> 
> Signed-off-by: Robert P. J. Day <rpjday@mindspring.com>
> 
> ---
> 
> According to:
> 
> http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Case-Ranges.html#Case-Ranges:
> 
>   "Be careful: Write spaces around the ..., for otherwise it may be
> parsed wrong when you use it with integer values."
> 
> 
> diff --git a/kernel/audit.c b/kernel/audit.c
> index 76c9a11..d963a04 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -515,8 +515,8 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)
>  			err = -EPERM;
>  		break;
>  	case AUDIT_USER:
> -	case AUDIT_FIRST_USER_MSG...AUDIT_LAST_USER_MSG:
> -	case AUDIT_FIRST_USER_MSG2...AUDIT_LAST_USER_MSG2:
> +	case AUDIT_FIRST_USER_MSG ... AUDIT_LAST_USER_MSG:
> +	case AUDIT_FIRST_USER_MSG2 ... AUDIT_LAST_USER_MSG2:

hm... We have: 

#define AUDIT_FIRST_USER_MSG    1100    /* Userspace messages mostly uninteresting to kernel */
#define AUDIT_USER_AVC          1107    /* We filter this differently */
#define AUDIT_LAST_USER_MSG     1199

and CPP turns that into

 case 1100 ...1199:
 case 2100 ...2999:

and it does the same when the comments are stripped from the #defines.

So we were saved by the trailing space which cpp added to the expanded
macro.  I wonder why cpp did that, and to what extent one can rely cpp
doing that.

Oh well.  I guess we should apply the patch.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Add spaces on either side of case "..." operator.
  2007-04-10 16:05 ` Andrew Morton
@ 2007-04-10 17:47   ` Jeremy Fitzhardinge
  2007-04-10 20:45     ` Alexey Dobriyan
  2007-04-10 20:37   ` Alexey Dobriyan
  1 sibling, 1 reply; 6+ messages in thread
From: Jeremy Fitzhardinge @ 2007-04-10 17:47 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Robert P. J. Day, Linux Kernel Mailing List

Andrew Morton wrote:
> #define AUDIT_FIRST_USER_MSG    1100    /* Userspace messages mostly uninteresting to kernel */
> #define AUDIT_USER_AVC          1107    /* We filter this differently */
> #define AUDIT_LAST_USER_MSG     1199
>
> and CPP turns that into
>
>  case 1100 ...1199:
>  case 2100 ...2999:
>
> and it does the same when the comments are stripped from the #defines.
>
> So we were saved by the trailing space which cpp added to the expanded
> macro.  I wonder why cpp did that, and to what extent one can rely cpp
> doing that.

I think its required to.  If it didn't, it would be effectively pasting
two tokens together without the ## operator.  But putting spaces in is
safer - or putting () around the numbers.

    J

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Add spaces on either side of case "..." operator.
  2007-04-10 16:05 ` Andrew Morton
  2007-04-10 17:47   ` Jeremy Fitzhardinge
@ 2007-04-10 20:37   ` Alexey Dobriyan
  1 sibling, 0 replies; 6+ messages in thread
From: Alexey Dobriyan @ 2007-04-10 20:37 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Robert P. J. Day, Linux Kernel Mailing List

On Tue, Apr 10, 2007 at 09:05:55AM -0700, Andrew Morton wrote:
> On Tue, 10 Apr 2007 07:23:35 -0400 (EDT) "Robert P. J. Day" <rpjday@mindspring.com> wrote:
> > Following the programming advice laid down in the gcc manual, make
> > sure the case "..." operator has spaces on either side.

> > http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Case-Ranges.html#Case-Ranges:
> >
> >   "Be careful: Write spaces around the ..., for otherwise it may be
> > parsed wrong when you use it with integer values."

> > --- a/kernel/audit.c
> > +++ b/kernel/audit.c
> > @@ -515,8 +515,8 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)
> >  			err = -EPERM;
> >  		break;
> >  	case AUDIT_USER:
> > -	case AUDIT_FIRST_USER_MSG...AUDIT_LAST_USER_MSG:
> > -	case AUDIT_FIRST_USER_MSG2...AUDIT_LAST_USER_MSG2:
> > +	case AUDIT_FIRST_USER_MSG ... AUDIT_LAST_USER_MSG:
> > +	case AUDIT_FIRST_USER_MSG2 ... AUDIT_LAST_USER_MSG2:
>
> hm... We have:
>
> #define AUDIT_FIRST_USER_MSG    1100    /* Userspace messages mostly uninteresting to kernel */
> #define AUDIT_USER_AVC          1107    /* We filter this differently */
> #define AUDIT_LAST_USER_MSG     1199
>
> and CPP turns that into
>
>  case 1100 ...1199:
>  case 2100 ...2999:
>
> and it does the same when the comments are stripped from the #defines.
>
> So we were saved by the trailing space which cpp added to the expanded
> macro.  I wonder why cpp did that, and to what extent one can rely cpp
> doing that.

The only reason I can come up with is temporary files with preprocessing
output. Imagine the code:

	#define FOO 1
	FOO.

Here we have
a) replacement list of token FOO consists of one token -- 1,
b) pp-token list after preprocessing consists of 4 pp-tokens: newline, 1, .,
   newline

BUT, write it to temporary file:

	
	1.

Whoops, there are 3 or 4 pp-tokens? If you don't know history, there are
3, if you do, there are 4.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Add spaces on either side of case "..." operator.
  2007-04-10 17:47   ` Jeremy Fitzhardinge
@ 2007-04-10 20:45     ` Alexey Dobriyan
  0 siblings, 0 replies; 6+ messages in thread
From: Alexey Dobriyan @ 2007-04-10 20:45 UTC (permalink / raw)
  To: Jeremy Fitzhardinge
  Cc: Andrew Morton, Robert P. J. Day, Linux Kernel Mailing List

On Tue, Apr 10, 2007 at 10:47:21AM -0700, Jeremy Fitzhardinge wrote:
> Andrew Morton wrote:
> > #define AUDIT_FIRST_USER_MSG    1100    /* Userspace messages mostly uninteresting to kernel */
> > #define AUDIT_USER_AVC          1107    /* We filter this differently */
> > #define AUDIT_LAST_USER_MSG     1199
> >
> > and CPP turns that into
> >
> >  case 1100 ...1199:
> >  case 2100 ...2999:
> >
> > and it does the same when the comments are stripped from the #defines.
> >
> > So we were saved by the trailing space which cpp added to the expanded
> > macro.  I wonder why cpp did that, and to what extent one can rely cpp
> > doing that.
>
> I think its required to.  If it didn't, it would be effectively pasting
> two tokens together without the ## operator.

Internally, there are lists of tokens and no ambiguities. What gcc docs
warn about is that

	case 1...2:

will be parsed as

	case
	[space]
	1.
	.
	.2
	:

which won't fly.

> But putting spaces in is safer - or putting () around the numbers.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-04-10 20:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-10 11:23 [PATCH] Add spaces on either side of case "..." operator Robert P. J. Day
2007-04-10 14:33 ` WANG Cong
2007-04-10 16:05 ` Andrew Morton
2007-04-10 17:47   ` Jeremy Fitzhardinge
2007-04-10 20:45     ` Alexey Dobriyan
2007-04-10 20:37   ` Alexey Dobriyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox