Re: 2.1.120pre2: Bug in strnicmp() noted in 2.1.119pre1 is still there!

Gabriel Paubert (paubert@iram.es)
Tue, 1 Sep 1998 12:30:29 +0200 (METDST)


On Tue, 1 Sep 1998, Michal Jaegermann wrote:

> Actually the following variation does not have any different
> "if-structure" and, has simpler block layout (easier on optimizer) and
> closes negative 'len' hole. 'len' likely should be an unsigned 'size_t'
> and not 'int' anyway.
>
> static int strnicmp(const char *s1, const char *s2, int len)
> {
> /* Yes, Virginia, it had better be unsigned */
> unsigned char c1, c2;
[snipped]

> "return (c1 - c2);" should be ok to safisfy specs, but if you insists
> on returning a sign replace this with:
> c1 =- c2;
> return c1 ? (c1 < 0 ? -1 : 1) : 0;

c1 being unsigned, it is unlikely to be negative :-) Even some versions
of the compiler would warn you about this (and the =- operator is
considered deprecated since ages). Apart from this, declaring char
unsigned or signed according to your needs is absolutely necessary. (For
portability you should never declare anything as plain char).

Linux/PPC for now has to be compiled with the -fsigned-char option for
some stupid reason, I shall try to fix it when time permits (not before
2.2 for sure).

People in countries where 8 bit character set are in wide use are often
more aware of these problems than English speaking ones, and basically
they will tell you that the only good char is the unsigned char.
(I can't remember having declared a signed char for years..., it happened
but it is extremely rare).

Gabriel.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html