Re: [PATCH]: improved strnicmp in lib/string.c

From: Pekka Enberg
Date: Wed May 07 2008 - 15:34:23 EST


On Wed, May 7, 2008 at 9:21 PM, Soumyadip Das Mahapatra
<dip_kernel@xxxxxxxxxxx> wrote:
> int strnicmp(const char *s1, const char *s2, size_t len)
> {
> + /* Yes, i am keeping 'em unsigned too */
> + unsigned char c1, c2, c3, c4;
> + unsigned count = 0;
> + int flag = -1;
> +
> + c1 = c2 = c3 = c4 = 0;
> +
> + if(len > 0)
> + {
> + for(; count <= len/2; count++)
> + {
> + c1 = tolower(s1[count]); // well, we
> + c2 = tolower(s2[count]); // are ignoring
> + c3 = tolower(s1[len-count-1]); // cases
> + c4 = tolower(s2[len-count-1]); // thats why
> +
> + if(c1 == c2)
> + {
> + if(c3 != c4)
> + {
> + flag = 1;
> + break;
> + }
> + }
> + else
> break;
> - } while (--len);
> + flag = 0;

Unconditionally setting flag to zero in the loop also broken. For
example, comparing "hello" and "he9lo" resunts into zero now.

> + }
> }
> - return (int)c1 - (int)c2;
> -}
> + return flag; // return 0 for matching and
> +} // nonzero for mismatch
> EXPORT_SYMBOL(strnicmp);
> #endif
>
>
>
> Meet people who discuss and share your passions. Go to http://in.promos.yahoo.com/groups/bestofyahoo/
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/