adjust array index
Subsystems (7)
cover adjust array index
These patches fix cases where the upper bound of a loop is used as an array indes, while it appears that the loop index should be used as the array index. I have only guessed that the code is incorrect, not actually tested any of it.
PATCH 1/6 net: adjust array index
From: Julia Lawall <[email protected]>
Convert array index from the loop bound to the loop index.
A simplified version of the semantic patch that fixes this problem is as
follows: (http://coccinelle.lip6.fr/)
// <smpl>
@@
expression e1,e2,ar;
@@
for(e1 = 0; e1 < e2; e1++) { <...
ar[
- e2
+ e1
]
...> }
// </smpl>
---
Not tested.
net/ipv4/igmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/igmp.c +1 -1
@@ -1718,7 +1718,7 @@ static int ip_mc_add_src(struct in_devic pmc->sfcount[sfmode]--;for (j=0 ; j<i; j++) - (void )ip_mc_del1_src (pmc, sfmode, &psfsrc[i]); + (void )ip_mc_del1_src (pmc, sfmode, &psfsrc[j]); }else if (isexclude != (pmc->sfcount[MCAST_EXCLUDE ] !=0 )) {#ifdef CONFIG_IP_MULTICAST struct ip_sf_list *psf;
Re: [PATCH 1/6] net: adjust array index
From: Julia Lawall <[email protected]>
Date: Thu, 28 Jul 2011 14:46:01 +0200
Quoted 20 lines
From: Julia Lawall <[email protected]>
Convert array index from the loop bound to the loop index.
A simplified version of the semantic patch that fixes this problem is as
follows: (http://coccinelle.lip6.fr/)// <smpl>
@@
expression e1,e2,ar;
@@for(e1 = 0; e1 < e2; e1++) { <...
ar[
- e2
+ e1
]
...> }
// </smpl>
Quoted 1 line
Signed-off-by Julia Lawall <[email protected]>
Applied.
PATCH 2/6 drivers/media/dvb/dvb-usb/usb-urb.c: adjust array index
In reply to Julia LawallFrom: Julia Lawall <[email protected]>
Convert array index from the loop bound to the loop index.
A simplified version of the semantic patch that fixes this problem is as
follows: (http://coccinelle.lip6.fr/)
// <smpl>
@@
expression e1,e2,ar;
@@
for(e1 = 0; e1 < e2; e1++) { <...
ar[
- e2
+ e1
]
...> }
// </smpl>
---
Not tested.
drivers/media/dvb/dvb-usb/usb-urb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/dvb/dvb-usb/usb-urb.c +2 -2
@@ -148,7 +148,7 @@ static int usb_bulk_urb_init(struct usb_if (!stream->urb_list[i]) {deb_mem ("not enough memory for urb_alloc_urb!.\n" );for (j =0 ; j < i; j++) -usb_free_urb (stream->urb_list[i]); +usb_free_urb (stream->urb_list[j]);return -ENOMEM ; } usb_fill_bulk_urb( stream->urb_list[i], stream->udev,
@@ -181,7 +181,7 @@ static int usb_isoc_urb_init(struct usb_if (!stream->urb_list[i]) {deb_mem ("not enough memory for urb_alloc_urb!\n" );for (j =0 ; j < i; j++) -usb_free_urb (stream->urb_list[i]); +usb_free_urb (stream->urb_list[j]);return -ENOMEM ; }
PATCH 3/6 drivers/net/niu.c: adjust array index
In reply to Julia LawallFrom: Julia Lawall <[email protected]>
Convert array index from the loop bound to the loop index.
A simplified version of the semantic patch that fixes this problem is as
follows: (http://coccinelle.lip6.fr/)
// <smpl>
@@
expression e1,e2,ar;
@@
for(e1 = 0; e1 < e2; e1++) { <...
ar[
- e2
+ e1
]
...> }
// </smpl>
---
Not tested.
drivers/net/niu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/niu.c +2 -2
@@ -9201,7 +9201,7 @@ static int __devinit niu_ldg_init(struct first_chan =0 ;for (i =0 ; i < port; i++) - first_chan += parent->rxchan_per_port[port]; + first_chan += parent->rxchan_per_port[i]; num_chan = parent->rxchan_per_port[port];for (i = first_chan; i < (first_chan + num_chan); i++) {
@@ -9217,7 +9217,7 @@ static int __devinit niu_ldg_init(struct first_chan =0 ;for (i =0 ; i < port; i++) - first_chan += parent->txchan_per_port[port]; + first_chan += parent->txchan_per_port[i]; num_chan = parent->txchan_per_port[port];for (i = first_chan; i < (first_chan + num_chan); i++) { err = niu_ldg_assign_ldn(np, parent,
Re: [PATCH 3/6] drivers/net/niu.c: adjust array index
From: Julia Lawall <[email protected]>
Date: Thu, 28 Jul 2011 14:46:03 +0200
Quoted 20 lines
From: Julia Lawall <[email protected]>
Convert array index from the loop bound to the loop index.
A simplified version of the semantic patch that fixes this problem is as
follows: (http://coccinelle.lip6.fr/)// <smpl>
@@
expression e1,e2,ar;
@@for(e1 = 0; e1 < e2; e1++) { <...
ar[
- e2
+ e1
]
...> }
// </smpl>
Quoted 1 line
Signed-off-by Julia Lawall <[email protected]>
Applied.
PATCH 4/6 drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c: adjust array index
In reply to Julia LawallFrom: Julia Lawall <[email protected]>
Convert array index from the loop bound to the loop index.
A simplified version of the semantic patch that fixes this problem is as
follows: (http://coccinelle.lip6.fr/)
// <smpl>
@@
expression e1,e2,ar;
@@
for(e1 = 0; e1 < e2; e1++) { <...
ar[
- e2
+ e1
]
...> }
// </smpl>
---
Not tested.
drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c +1 -1
@@ -812,7 +812,7 @@ int AthCreateCommandList(struct ps_cmd_pfor (count =0 ; count < Patch_Count; count++) {AR_DEBUG_PRINTF (ATH_DEBUG_ERR ,("Freeing Patch Buffer %d \r\n" ,count)); -kfree (RamPatch[Patch_Count].Data); +kfree (RamPatch[count].Data); }for (count =0 ; count < Tag_Count; count++) {
PATCH 5/6 sound/core/pcm_compat.c: adjust array index
In reply to Julia LawallFrom: Julia Lawall <[email protected]>
Convert array index from the loop bound to the loop index.
A simplified version of the semantic patch that fixes this problem is as
follows: (http://coccinelle.lip6.fr/)
// <smpl>
@@
expression e1,e2,ar;
@@
for(e1 = 0; e1 < e2; e1++) { <...
ar[
- e2
+ e1
]
...> }
// </smpl>
---
Not tested.
sound/core/pcm_compat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/pcm_compat.c +1 -1
@@ -342,7 +342,7 @@ static int snd_pcm_ioctl_xfern_compat(stkfree (bufs);return -EFAULT ; } - bufs[ch] =compat_ptr (ptr); + bufs[i] =compat_ptr (ptr); bufptr++; }if (dir =SNDRV_PCM_STREAM_PLAYBACK )
Takashi Iwai
AppliedRe: [PATCH 5/6] sound/core/pcm_compat.c: adjust array index
At Thu, 28 Jul 2011 14:46:05 +0200,
Quoted 21 lines · Julia Lawall
From: Julia Lawall <[email protected]>
Convert array index from the loop bound to the loop index.
A simplified version of the semantic patch that fixes this problem is as
follows: (http://coccinelle.lip6.fr/)// <smpl>
@@
expression e1,e2,ar;
@@for(e1 = 0; e1 < e2; e1++) { <...
ar[
- e2
+ e1
]
...> }
// </smpl>
Quoted 1 line
Signed-off-by Julia Lawall <[email protected]>
Thanks, applied now.
Takashi
Quoted 20 lines
---
Not tested.sound/core/pcm_compat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)diff -u -p
a/sound/core/pcm_compat.cb/sound/core/pcm_compat.csound/core/pcm_compat.c +1
-1@@ -342,7 +342,7 @@ static int snd_pcm_ioctl_xfern_compat(stkfree (bufs);return -EFAULT ; } - bufs[ch] =compat_ptr (ptr); + bufs[i] =compat_ptr (ptr); bufptr++; }if (dir ==SNDRV_PCM_STREAM_PLAYBACK )
Quoted 3 lines · Julia Lawall
These patches fix cases where the upper bound of a loop is used as an array index, while it appears that the loop index should be used as the array index.
Good one.