lkml.org 
[lkml]   [2003]   [Jan]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [BUG] in drivers/char/joystick/magellan.c
Date
From
Vojtech Pavlik <vojtech@suse.cz> said:
> On Tue, Jan 28, 2003 at 04:53:12PM +0100, Jörn Engel wrote:
> > Hi!
> >
> > Without the patch below, the \0 terminating the string is written
> > anywhere.

No. As the length is explicitly given, C will just fill out that many bytes
from the given string.

> > nibbles[] would be even better, I guess.
>
> Well, the zero isn't used, so it might make sense to use '0', 'A', 'B' ...
> ... though that's not very nice either.
>
> > Can you check for stupidity on my side?
>
> Can't find any. ;) Patch applied with [].

> > diff -Naur linux-2.4.21-pre3-ac4/drivers/char/joystick/magellan.c scratch/dri
> vers/char/joystick/magellan.c
> > --- linux-2.4.21-pre3-ac4/drivers/char/joystick/magellan.c Thu Sep 13 00:3
> 4:06 2001
> > +++ scratch/drivers/char/joystick/magellan.c Mon Jan 27 13:49:54 2003
> > @@ -66,7 +66,7 @@
> >
> > static int magellan_crunch_nibbles(unsigned char *data, int count)
> > {
> > - static unsigned char nibbles[16] = "0AB3D56GH9:K<MN?";
> > + static unsigned char nibbles[17] = "0AB3D56GH9:K<MN?";
> >
> > do {
> > if (data[count] == nibbles[data[count] & 0xf])

C says only the first 16 bytes get used as initializer, i.e., the '\0' is
(silently) discarded. The patch makes the array grow, for no reason; thus
making its read-only data usage probably 4 or even 16 bytes (padding)
larger.

Sure, it can be argued that this is bad style as nibbles[] really isn't a
string, and should not be initialized like such... but

static unsigned char nibbles[] = {'0', 'A', ..., '?'};

is just awful.

Please leave it alone, or add a comment like:

/* nibbles is no string, it is just initialized as such for convenience */
--
Dr. Horst H. von Brand User #22616 counter.li.org
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:32    [W:0.058 / U:0.252 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site