lkml.org 
[lkml]   [1998]   [Sep]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
FromMichal Jaegermann <>
SubjectRe: 2.1.120pre2: Bug in strnicmp() noted in 2.1.119pre1 is still there!
DateTue, 1 Sep 1998 00:46:49 -0600 (MDT)

Hans Eric wrote:
>
> Cool, creative use of gotos keeps nested ifs to a minimum.

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;
if (len <= 0)
return 0;
while (len) {
c1 = *s1; c2 = *s2;
s1++; s2++;
if (c1 == '\0' || c2 == '\0')
break;
if (c1 != c2) {
c1 = tolower(c1);
c2 = tolower(c2);
if (c1 != c2)
break;
}
len--;
}
return (c1 - c2);
}
"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;

Michal
michal@harddata.com

-
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

\
 
 \ /
  Last update: 2005-03-22 13:44    [from the cache]
©2003-2010