public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] kernel/sched.c: Fix array initialization typo
@ 2011-06-12 21:31 Jean Sacren
  2011-06-12 21:35 ` Alexey Dobriyan
  2011-06-14 18:49 ` Valdis.Kletnieks
  0 siblings, 2 replies; 7+ messages in thread
From: Jean Sacren @ 2011-06-12 21:31 UTC (permalink / raw)
  To: Linux Kernel Mailing List

The fix makes certain so that the size of the initialized arrays doesn't
go beyond the boundary set by the array size of 40.

Signed-off-by: Jean Sacren <sakiwit@gmail.com>
---
 kernel/sched.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index c164920..c29ddd0 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -1383,7 +1383,7 @@ static const int prio_to_weight[40] = {
  /*   0 */      1024,       820,       655,       526,       423,
  /*   5 */       335,       272,       215,       172,       137,
  /*  10 */       110,        87,        70,        56,        45,
- /*  15 */        36,        29,        23,        18,        15,
+ /*  15 */        36,        29,        23,        18,        15
 };
 
 /*
@@ -1401,7 +1401,7 @@ static const u32 prio_to_wmult[40] = {
  /*   0 */   4194304,   5237765,   6557202,   8165337,  10153587,
  /*   5 */  12820798,  15790321,  19976592,  24970740,  31350126,
  /*  10 */  39045157,  49367440,  61356676,  76695844,  95443717,
- /*  15 */ 119304647, 148102320, 186737708, 238609294, 286331153,
+ /*  15 */ 119304647, 148102320, 186737708, 238609294, 286331153
 };
 
 /* Time spent by the tasks of the cpu accounting group executing in ... */
-- 
1.7.2.2

-- 
Jean Sacren

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

* Re: [PATCH 1/1] kernel/sched.c: Fix array initialization typo
  2011-06-12 21:31 [PATCH 1/1] kernel/sched.c: Fix array initialization typo Jean Sacren
@ 2011-06-12 21:35 ` Alexey Dobriyan
  2011-06-12 22:01   ` Jean Sacren
  2011-06-14 18:49 ` Valdis.Kletnieks
  1 sibling, 1 reply; 7+ messages in thread
From: Alexey Dobriyan @ 2011-06-12 21:35 UTC (permalink / raw)
  To: Jean Sacren; +Cc: Linux Kernel Mailing List

On Sun, Jun 12, 2011 at 03:31:07PM -0600, Jean Sacren wrote:
> The fix makes certain so that the size of the initialized arrays doesn't
> go beyond the boundary set by the array size of 40.

Why would it possibly do that?

And it's not a typo.

> @@ -1383,7 +1383,7 @@ static const int prio_to_weight[40] = {
>   /*   0 */      1024,       820,       655,       526,       423,
>   /*   5 */       335,       272,       215,       172,       137,
>   /*  10 */       110,        87,        70,        56,        45,
> - /*  15 */        36,        29,        23,        18,        15,
> + /*  15 */        36,        29,        23,        18,        15
>  };
>  
>  /*
> @@ -1401,7 +1401,7 @@ static const u32 prio_to_wmult[40] = {
>   /*   0 */   4194304,   5237765,   6557202,   8165337,  10153587,
>   /*   5 */  12820798,  15790321,  19976592,  24970740,  31350126,
>   /*  10 */  39045157,  49367440,  61356676,  76695844,  95443717,
> - /*  15 */ 119304647, 148102320, 186737708, 238609294, 286331153,
> + /*  15 */ 119304647, 148102320, 186737708, 238609294, 286331153
>  };

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

* Re: [PATCH 1/1] kernel/sched.c: Fix array initialization typo
  2011-06-12 21:35 ` Alexey Dobriyan
@ 2011-06-12 22:01   ` Jean Sacren
  2011-06-12 23:09     ` Andy Isaacson
  0 siblings, 1 reply; 7+ messages in thread
From: Jean Sacren @ 2011-06-12 22:01 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: Linux Kernel Mailing List

From: Alexey Dobriyan <adobriyan@gmail.com>
Date: Mon, 13 Jun 2011 00:35:49 +0300
>
> On Sun, Jun 12, 2011 at 03:31:07PM -0600, Jean Sacren wrote:
> > The fix makes certain so that the size of the initialized arrays doesn't
> > go beyond the boundary set by the array size of 40.
> 
> Why would it possibly do that?

With that ',' comma, doesn't it imply there might be the 41st element in
the array? Despite the fact that that element is bogus.

Further, if the comma is there, what's the benefit? I know you're cool,
but is it cool in code that way as well?
> 
> And it's not a typo.

What is it then?
> 
> > @@ -1383,7 +1383,7 @@ static const int prio_to_weight[40] = {
> >   /*   0 */      1024,       820,       655,       526,       423,
> >   /*   5 */       335,       272,       215,       172,       137,
> >   /*  10 */       110,        87,        70,        56,        45,
> > - /*  15 */        36,        29,        23,        18,        15,
> > + /*  15 */        36,        29,        23,        18,        15
> >  };
> >  
> >  /*
> > @@ -1401,7 +1401,7 @@ static const u32 prio_to_wmult[40] = {
> >   /*   0 */   4194304,   5237765,   6557202,   8165337,  10153587,
> >   /*   5 */  12820798,  15790321,  19976592,  24970740,  31350126,
> >   /*  10 */  39045157,  49367440,  61356676,  76695844,  95443717,
> > - /*  15 */ 119304647, 148102320, 186737708, 238609294, 286331153,
> > + /*  15 */ 119304647, 148102320, 186737708, 238609294, 286331153
> >  };

-- 
Jean Sacren

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

* Re: [PATCH 1/1] kernel/sched.c: Fix array initialization typo
  2011-06-12 22:01   ` Jean Sacren
@ 2011-06-12 23:09     ` Andy Isaacson
  2011-06-12 23:59       ` Randy Dunlap
  2011-06-13  0:51       ` Jean Sacren
  0 siblings, 2 replies; 7+ messages in thread
From: Andy Isaacson @ 2011-06-12 23:09 UTC (permalink / raw)
  To: Jean Sacren; +Cc: Alexey Dobriyan, Linux Kernel Mailing List

On Sun, Jun 12, 2011 at 04:01:16PM -0600, Jean Sacren wrote:
> From: Alexey Dobriyan <adobriyan@gmail.com>
> Date: Mon, 13 Jun 2011 00:35:49 +0300
> >
> > On Sun, Jun 12, 2011 at 03:31:07PM -0600, Jean Sacren wrote:
> > > The fix makes certain so that the size of the initialized arrays doesn't
> > > go beyond the boundary set by the array size of 40.
> > 
> > Why would it possibly do that?
> 
> With that ',' comma, doesn't it imply there might be the 41st element in
> the array?

No, that's not how C works.

> Despite the fact that that element is bogus.

It's not bogus, it's utterly cromulent.  Trailing comma on array
initializer was mentioned in the original K&R and is explicitly endorsed
by ISO/IEC 9899:1999 6.7.8 paragraph 1.

> Further, if the comma is there, what's the benefit? I know you're cool,
> but is it cool in code that way as well?
> > 
> > And it's not a typo.
> 
> What is it then?

It is a standard C idiom for defining array contents.  If you write
int x[] = {
    1,
    2,
    3
};

then when I add a fourth element to your array, I have to modify two
lines, and the diff will say
-    3
+    3,
+    4
 };

whereas if you wrote "3," as the last line of the initializer, the diff
would be one line long.

Furthermore, spot the error in this diff:

@@ -3,4 +3,5 @@ char *x[] = {
     "quick",
     "brown",
     "fox"
+    "jumped"
 };

HTH, HAND,
-andy

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

* Re: [PATCH 1/1] kernel/sched.c: Fix array initialization typo
  2011-06-12 23:09     ` Andy Isaacson
@ 2011-06-12 23:59       ` Randy Dunlap
  2011-06-13  0:51       ` Jean Sacren
  1 sibling, 0 replies; 7+ messages in thread
From: Randy Dunlap @ 2011-06-12 23:59 UTC (permalink / raw)
  To: Andy Isaacson; +Cc: Jean Sacren, Alexey Dobriyan, Linux Kernel Mailing List

On Sun, 12 Jun 2011 16:09:01 -0700 Andy Isaacson wrote:

> On Sun, Jun 12, 2011 at 04:01:16PM -0600, Jean Sacren wrote:
> > From: Alexey Dobriyan <adobriyan@gmail.com>
> > Date: Mon, 13 Jun 2011 00:35:49 +0300
> > >
> > > On Sun, Jun 12, 2011 at 03:31:07PM -0600, Jean Sacren wrote:
> > > > The fix makes certain so that the size of the initialized arrays doesn't
> > > > go beyond the boundary set by the array size of 40.
> > > 
> > > Why would it possibly do that?
> > 
> > With that ',' comma, doesn't it imply there might be the 41st element in
> > the array?
> 
> No, that's not how C works.
> 
> > Despite the fact that that element is bogus.
> 
> It's not bogus, it's utterly cromulent.  Trailing comma on array
> initializer was mentioned in the original K&R and is explicitly endorsed
> by ISO/IEC 9899:1999 6.7.8 paragraph 1.
> 
> > Further, if the comma is there, what's the benefit? I know you're cool,
> > but is it cool in code that way as well?
> > > 
> > > And it's not a typo.
> > 
> > What is it then?
> 
> It is a standard C idiom for defining array contents.  If you write

ack.  I once worked on on OS where the common idiom for array inits was:

int x[] = {
	1
,	2
,	3
};

so that additions only required one line of change.

> int x[] = {
>     1,
>     2,
>     3
> };
> 
> then when I add a fourth element to your array, I have to modify two
> lines, and the diff will say
> -    3
> +    3,
> +    4
>  };
> 
> whereas if you wrote "3," as the last line of the initializer, the diff
> would be one line long.
> 
> Furthermore, spot the error in this diff:
> 
> @@ -3,4 +3,5 @@ char *x[] = {
>      "quick",
>      "brown",
>      "fox"
> +    "jumped"
>  };



---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* Re: [PATCH 1/1] kernel/sched.c: Fix array initialization typo
  2011-06-12 23:09     ` Andy Isaacson
  2011-06-12 23:59       ` Randy Dunlap
@ 2011-06-13  0:51       ` Jean Sacren
  1 sibling, 0 replies; 7+ messages in thread
From: Jean Sacren @ 2011-06-13  0:51 UTC (permalink / raw)
  To: Andy Isaacson; +Cc: Linux Kernel Mailing List

From: Andy Isaacson <adi@hexapodia.org>
Date: Sun, 12 Jun 2011 16:09:01 -0700
>
> It is a standard C idiom for defining array contents.  If you write
> int x[] = {
>     1,
>     2,
>     3
> };
> 
> then when I add a fourth element to your array, I have to modify two
> lines, and the diff will say
> -    3
> +    3,
> +    4
>  };
> 
> whereas if you wrote "3," as the last line of the initializer, the diff
> would be one line long.

I don't know how to thank you for this. Apparently the patch is bogus.
> 
> Furthermore, spot the error in this diff:
> 
> @@ -3,4 +3,5 @@ char *x[] = {
>      "quick",
>      "brown",
>      "fox"
> +    "jumped"
>  };
> 
> HTH, HAND,
> -andy

-- 
Jean Sacren

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

* Re: [PATCH 1/1] kernel/sched.c: Fix array initialization typo
  2011-06-12 21:31 [PATCH 1/1] kernel/sched.c: Fix array initialization typo Jean Sacren
  2011-06-12 21:35 ` Alexey Dobriyan
@ 2011-06-14 18:49 ` Valdis.Kletnieks
  1 sibling, 0 replies; 7+ messages in thread
From: Valdis.Kletnieks @ 2011-06-14 18:49 UTC (permalink / raw)
  To: Jean Sacren; +Cc: Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 668 bytes --]

On Sun, 12 Jun 2011 15:31:07 MDT, Jean Sacren said:
> The fix makes certain so that the size of the initialized arrays doesn't
> go beyond the boundary set by the array size of 40.

Did you notice that gcc as far back as 3.4.6 will whinge *anyhow*
if you have too many initializers?

% cat > test9.c
int foo[5] = { 0, 1, 2, 3, 4, 5, 6};
^D
% gcc -c test9.c
test9.c:1:1: warning: excess elements in array initializer [enabled by default]
test9.c:1:1: warning: (near initialization for 'foo') [enabled by default]
test9.c:1:1: warning: excess elements in array initializer [enabled by default]
test9.c:1:1: warning: (near initialization for 'foo') [enabled by default]


[-- Attachment #2: Type: application/pgp-signature, Size: 227 bytes --]

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

end of thread, other threads:[~2011-06-14 18:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-12 21:31 [PATCH 1/1] kernel/sched.c: Fix array initialization typo Jean Sacren
2011-06-12 21:35 ` Alexey Dobriyan
2011-06-12 22:01   ` Jean Sacren
2011-06-12 23:09     ` Andy Isaacson
2011-06-12 23:59       ` Randy Dunlap
2011-06-13  0:51       ` Jean Sacren
2011-06-14 18:49 ` Valdis.Kletnieks

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