From: "Pekka Enberg" <penberg@cs.helsinki.fi>
To: "Soumyadip Das Mahapatra" <dip_kernel@yahoo.co.in>
Cc: linux-kernel@vger.kernel.org, "Alexey Dobriyan" <adobriyan@gmail.com>
Subject: Re: [PATCH]: improved strnicmp in lib/string.c
Date: Wed, 7 May 2008 22:33:57 +0300 [thread overview]
Message-ID: <84144f020805071233u5ebaaa4fgfd6beccd36c873f0@mail.gmail.com> (raw)
In-Reply-To: <116786.40929.qm@web94104.mail.in2.yahoo.com>
On Wed, May 7, 2008 at 9:21 PM, Soumyadip Das Mahapatra
<dip_kernel@yahoo.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@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
next prev parent reply other threads:[~2008-05-07 19:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-07 18:21 Soumyadip Das Mahapatra
2008-05-07 19:33 ` Pekka Enberg [this message]
2008-05-07 19:53 ` Alexey Dobriyan
2008-05-08 1:14 ` David Newall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=84144f020805071233u5ebaaa4fgfd6beccd36c873f0@mail.gmail.com \
--to=penberg@cs.helsinki.fi \
--cc=adobriyan@gmail.com \
--cc=dip_kernel@yahoo.co.in \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®