* [Patch] Off by one in drivers/usb/input/yealink.c
@ 2006-06-27 22:41 Eric Sesterhenn
2006-06-27 22:51 ` Randy.Dunlap
0 siblings, 1 reply; 9+ messages in thread
From: Eric Sesterhenn @ 2006-06-27 22:41 UTC (permalink / raw)
To: linux-kernel; +Cc: Henk.Vergonet
hi,
another off by one spotted by coverity (id #485),
we loop exactly one time too often
Signed-off-by: Eric Sesterhenn <snakebyte@gmx.de>
--- linux-2.6.17-git11/drivers/usb/input/yealink.c.orig 2006-06-28 00:29:46.000000000 +0200
+++ linux-2.6.17-git11/drivers/usb/input/yealink.c 2006-06-28 00:30:04.000000000 +0200
@@ -350,7 +350,7 @@ static int yealink_do_idle_tasks(struct
val = yld->master.b[ix];
if (val != yld->copy.b[ix])
goto send_update;
- } while (++ix < sizeof(yld->master));
+ } while (++ix < sizeof(yld->master)-1);
/* nothing todo, wait a bit and poll for a KEYPRESS */
yld->stat_ix = 0;
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch] Off by one in drivers/usb/input/yealink.c
2006-06-27 22:41 [Patch] Off by one in drivers/usb/input/yealink.c Eric Sesterhenn
@ 2006-06-27 22:51 ` Randy.Dunlap
2006-06-27 23:04 ` Eric Sesterhenn / Snakebyte
2006-07-05 13:02 ` Henk Vergonet
0 siblings, 2 replies; 9+ messages in thread
From: Randy.Dunlap @ 2006-06-27 22:51 UTC (permalink / raw)
To: Eric Sesterhenn; +Cc: linux-kernel, Henk.Vergonet
On Wed, 28 Jun 2006 00:41:19 +0200 Eric Sesterhenn wrote:
> hi,
>
> another off by one spotted by coverity (id #485),
> we loop exactly one time too often
>
> Signed-off-by: Eric Sesterhenn <snakebyte@gmx.de>
>
> --- linux-2.6.17-git11/drivers/usb/input/yealink.c.orig 2006-06-28 00:29:46.000000000 +0200
> +++ linux-2.6.17-git11/drivers/usb/input/yealink.c 2006-06-28 00:30:04.000000000 +0200
> @@ -350,7 +350,7 @@ static int yealink_do_idle_tasks(struct
> val = yld->master.b[ix];
> if (val != yld->copy.b[ix])
> goto send_update;
> - } while (++ix < sizeof(yld->master));
> + } while (++ix < sizeof(yld->master)-1);
>
> /* nothing todo, wait a bit and poll for a KEYPRESS */
> yld->stat_ix = 0;
FWIW, on this one and the previous floppy.c patch,
I would rather see the comparison be <= instead of using -1.
---
~Randy
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch] Off by one in drivers/usb/input/yealink.c
2006-06-27 22:51 ` Randy.Dunlap
@ 2006-06-27 23:04 ` Eric Sesterhenn / Snakebyte
2006-06-27 23:18 ` Randy.Dunlap
2006-07-05 13:02 ` Henk Vergonet
1 sibling, 1 reply; 9+ messages in thread
From: Eric Sesterhenn / Snakebyte @ 2006-06-27 23:04 UTC (permalink / raw)
To: Randy.Dunlap; +Cc: Eric Sesterhenn, linux-kernel, Henk.Vergonet
* Randy.Dunlap (rdunlap@xenotime.net) wrote:
> On Wed, 28 Jun 2006 00:41:19 +0200 Eric Sesterhenn wrote:
>
> > hi,
> >
> > another off by one spotted by coverity (id #485),
> > we loop exactly one time too often
> >
> > Signed-off-by: Eric Sesterhenn <snakebyte@gmx.de>
> >
> > --- linux-2.6.17-git11/drivers/usb/input/yealink.c.orig 2006-06-28 00:29:46.000000000 +0200
> > +++ linux-2.6.17-git11/drivers/usb/input/yealink.c 2006-06-28 00:30:04.000000000 +0200
> > @@ -350,7 +350,7 @@ static int yealink_do_idle_tasks(struct
> > val = yld->master.b[ix];
> > if (val != yld->copy.b[ix])
> > goto send_update;
> > - } while (++ix < sizeof(yld->master));
> > + } while (++ix < sizeof(yld->master)-1);
> >
> > /* nothing todo, wait a bit and poll for a KEYPRESS */
> > yld->stat_ix = 0;
>
> FWIW, on this one and the previous floppy.c patch,
> I would rather see the comparison be <= instead of using -1.
maybe it is too late, but wouldnt the <= make the loop
run even more iterations, like (++ix < sizeof() + 1)
greetings, Eric
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch] Off by one in drivers/usb/input/yealink.c
2006-06-27 23:04 ` Eric Sesterhenn / Snakebyte
@ 2006-06-27 23:18 ` Randy.Dunlap
2006-06-27 23:26 ` Eric Sesterhenn
0 siblings, 1 reply; 9+ messages in thread
From: Randy.Dunlap @ 2006-06-27 23:18 UTC (permalink / raw)
To: Eric Sesterhenn / Snakebyte; +Cc: snakebyte, linux-kernel, Henk.Vergonet
On Wed, 28 Jun 2006 01:04:16 +0200 Eric Sesterhenn / Snakebyte wrote:
> * Randy.Dunlap (rdunlap@xenotime.net) wrote:
> > On Wed, 28 Jun 2006 00:41:19 +0200 Eric Sesterhenn wrote:
> >
> > > another off by one spotted by coverity (id #485),
> > > we loop exactly one time too often
> > >
> > > --- linux-2.6.17-git11/drivers/usb/input/yealink.c.orig 2006-06-28 00:29:46.000000000 +0200
> > > +++ linux-2.6.17-git11/drivers/usb/input/yealink.c 2006-06-28 00:30:04.000000000 +0200
> > > @@ -350,7 +350,7 @@ static int yealink_do_idle_tasks(struct
> > > val = yld->master.b[ix];
> > > if (val != yld->copy.b[ix])
> > > goto send_update;
> > > - } while (++ix < sizeof(yld->master));
> > > + } while (++ix < sizeof(yld->master)-1);
> > >
> > > /* nothing todo, wait a bit and poll for a KEYPRESS */
> > > yld->stat_ix = 0;
> >
> > FWIW, on this one and the previous floppy.c patch,
> > I would rather see the comparison be <= instead of using -1.
>
> maybe it is too late, but wouldnt the <= make the loop
> run even more iterations, like (++ix < sizeof() + 1)
:) Yep.
so for the floppy.c patch, I still prefer to see:
+ if (drive < 0 || drive >= N_DRIVE) {
instead of
+ if (drive < 0 || drive > N_DRIVE-1) {
Does that make sense?
---
~Randy
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [Patch] Off by one in drivers/usb/input/yealink.c
2006-06-27 23:18 ` Randy.Dunlap
@ 2006-06-27 23:26 ` Eric Sesterhenn
0 siblings, 0 replies; 9+ messages in thread
From: Eric Sesterhenn @ 2006-06-27 23:26 UTC (permalink / raw)
To: Randy.Dunlap; +Cc: linux-kernel, Henk.Vergonet
> :) Yep.
>
> so for the floppy.c patch, I still prefer to see:
> + if (drive < 0 || drive >= N_DRIVE) {
>
> instead of
> + if (drive < 0 || drive > N_DRIVE-1) {
>
> Does that make sense?
looks better :)
---
another bug spotted by coverity (id #481).
In the case that drive == N_DRIVE we acess past the
drive_params array which is defined as
drive_params[N_DRIVE]. By using the UDP define
in the else case because UDP is &drive_params[drive]
Signed-off-by: Eric Sesterhenn <snakebyte@gmx.de>
--- linux-2.6.17-git11/drivers/block/floppy.c.orig 2006-06-28 01:22:59.000000000 +0200
+++ linux-2.6.17-git11/drivers/block/floppy.c 2006-06-28 01:23:24.000000000 +0200
@@ -684,7 +684,7 @@ static void __reschedule_timeout(int dri
if (drive == current_reqD)
drive = current_drive;
del_timer(&fd_timeout);
- if (drive < 0 || drive > N_DRIVE) {
+ if (drive < 0 || drive >= N_DRIVE) {
fd_timeout.expires = jiffies + 20UL * HZ;
drive = 0;
} else
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch] Off by one in drivers/usb/input/yealink.c
2006-06-27 22:51 ` Randy.Dunlap
2006-06-27 23:04 ` Eric Sesterhenn / Snakebyte
@ 2006-07-05 13:02 ` Henk Vergonet
[not found] ` <d120d5000607050655o44cb66c3s7616493c7507d4d8@mail.gmail.com>
1 sibling, 1 reply; 9+ messages in thread
From: Henk Vergonet @ 2006-07-05 13:02 UTC (permalink / raw)
To: Randy.Dunlap; +Cc: Eric Sesterhenn, linux-kernel
Sorry for the late response guys, but I was on holliday.
No no no, please dont use this.
On Tue, Jun 27, 2006 at 03:51:43PM -0700, Randy.Dunlap wrote:
> On Wed, 28 Jun 2006 00:41:19 +0200 Eric Sesterhenn wrote:
> > another off by one spotted by coverity (id #485),
> > we loop exactly one time too often
> >
> > Signed-off-by: Eric Sesterhenn <snakebyte@gmx.de>
> >
> > --- linux-2.6.17-git11/drivers/usb/input/yealink.c.orig 2006-06-28 00:29:46.000000000 +0200
> > +++ linux-2.6.17-git11/drivers/usb/input/yealink.c 2006-06-28 00:30:04.000000000 +0200
> > @@ -350,7 +350,7 @@ static int yealink_do_idle_tasks(struct
> > val = yld->master.b[ix];
> > if (val != yld->copy.b[ix])
> > goto send_update;
> > - } while (++ix < sizeof(yld->master));
> > + } while (++ix < sizeof(yld->master)-1);
Apart from introducing a new bug in the code, the construct is ugly.
I would rather see then the more readable:
ix++;
} while (ix < sizeof(yld->master));
- Henk
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2006-07-06 14:41 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-27 22:41 [Patch] Off by one in drivers/usb/input/yealink.c Eric Sesterhenn
2006-06-27 22:51 ` Randy.Dunlap
2006-06-27 23:04 ` Eric Sesterhenn / Snakebyte
2006-06-27 23:18 ` Randy.Dunlap
2006-06-27 23:26 ` Eric Sesterhenn
2006-07-05 13:02 ` Henk Vergonet
[not found] ` <d120d5000607050655o44cb66c3s7616493c7507d4d8@mail.gmail.com>
2006-07-06 0:49 ` Eric Sesterhenn / Snakebyte
2006-07-06 2:25 ` Dmitry Torokhov
2006-07-06 14:41 ` Eric Sesterhenn / Snakebyte
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox