[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <84144f020805071233u5ebaaa4fgfd6beccd36c873f0@mail.gmail.com>
Date: Wed, 7 May 2008 22:33:57 +0300
From: "Pekka Enberg" <penberg@...helsinki.fi>
To: "Soumyadip Das Mahapatra" <dip_kernel@...oo.co.in>
Cc: linux-kernel@...r.kernel.org,
"Alexey Dobriyan" <adobriyan@...il.com>
Subject: Re: [PATCH]: improved strnicmp in lib/string.c
On Wed, May 7, 2008 at 9:21 PM, Soumyadip Das Mahapatra
<dip_kernel@...oo.co.in> 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@...r.kernel.org
> 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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists