From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH V2 2/8] string: fix strncmp function
Date: Wed, 18 Dec 2013 12:52:03 +0000 [thread overview]
Message-ID: <20131218125203.GI4360@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <52B193BE.1080206@gmail.com>
On Wed, Dec 18, 2013 at 01:23:26PM +0100, Daniel Mack wrote:
> On 12/18/2013 01:15 PM, Russell King - ARM Linux wrote:
> > For instance, can you be sure that there aren't any uses of strncmp()
> > which already test for less-than-zero etc?
>
> In this case, yes. The code as it stands is very small, and users only
> check for the return value of these functions to be 0.
>
> But I wonder whether that patch is needed at all. At least the rest of
> this series does not even seem to introduce new call sites of strcmp()
> or strncmp() ...
The implementation appears to be buggy as it stands - all it does is
sum up the differences in the whole string.
What if you're comparing two strings:
ac
ca
The first character has a difference of +2, the second has a difference
of -2. Sum those together and you get zero. Oh, the two strings are
identical!
Oh, and the other nitpick with the code is this:
*(a++)
Really, are those parens really needed? If you don't know the precendence
there, then you really shouldn't be programming in C, because this might
also be buggy:
*(a++) - *(b++)
because if we declare that we don't know the precedence rules, it could be
that this is evaluated as *((a++) - (*(b++))) which would lead to errors!
Maybe some more parens should be added to make it clear! Or maybe we
should just learn the precedence rules and realise that:
*a++ - *b++
is correct and clear and there's no need for any stupid idiotic parens
here.
Yes, I loath unnecessary parens.
next prev parent reply other threads:[~2013-12-18 12:52 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-11 13:07 [PATCH 0/8] Impedance matcher for Samsung boards Piotr Wilczek
2013-12-11 13:07 ` [PATCH 1/8] registers: add write u8 type Piotr Wilczek
2013-12-11 13:07 ` [PATCH 2/8] string: fix strncmp function Piotr Wilczek
2013-12-11 13:07 ` [PATCH 3/8] device tree blob must be 4-bytes alingned Piotr Wilczek
2013-12-11 13:07 ` [PATCH 4/8] Makefile: disable generating Thumb code Piotr Wilczek
2013-12-11 13:07 ` [PATCH 5/8] add memory operations Piotr Wilczek
2013-12-11 13:07 ` [PATCH 7/8] serial: add Exynos specific serial driver Piotr Wilczek
2013-12-11 13:07 ` [PATCH 8/8] board: add Samsung specific board support Piotr Wilczek
2013-12-11 13:16 ` [PATCH 0/8] Impedance matcher for Samsung boards Daniel Mack
2013-12-11 14:03 ` Piotr Wilczek
2013-12-11 14:10 ` Daniel Mack
2013-12-11 14:28 ` Tomasz Figa
2013-12-11 15:19 ` Daniel Mack
2013-12-11 15:48 ` Nicolas Pitre
2013-12-11 19:06 ` Jason Cooper
[not found] ` <1386767259-15693-7-git-send-email-p.wilczek@samsung.com>
2013-12-11 19:00 ` [PATCH 6/8] add support to supplement atags to device tree Jason Cooper
2013-12-12 12:09 ` Piotr Wilczek
2013-12-12 12:36 ` Jason Cooper
2013-12-18 12:09 ` [PATCH V2 0/8] Impedance matcher for Samsung boards Piotr Wilczek
2013-12-18 12:09 ` [PATCH V2 1/8] registers: add write u8 type Piotr Wilczek
2013-12-18 12:09 ` [PATCH V2 2/8] string: fix strncmp function Piotr Wilczek
2013-12-18 12:15 ` Russell King - ARM Linux
2013-12-18 12:23 ` Daniel Mack
2013-12-18 12:52 ` Russell King - ARM Linux [this message]
2013-12-18 16:01 ` Jason Cooper
2013-12-18 18:50 ` Jason Cooper
2013-12-18 18:56 ` Jason Cooper
2013-12-18 16:03 ` Jason Cooper
2013-12-18 16:04 ` Daniel Mack
2013-12-18 12:50 ` Piotr Wilczek
2013-12-18 12:09 ` [PATCH V2 3/8] device tree blob must be 4-bytes alingned Piotr Wilczek
2013-12-18 12:09 ` [PATCH V2 4/8] Makefile: disable generating Thumb code Piotr Wilczek
2013-12-18 12:09 ` [PATCH V2 5/8] add memory operations Piotr Wilczek
2013-12-18 12:09 ` [PATCH V2 7/8] serial: add Exynos specific serial driver Piotr Wilczek
2013-12-18 12:09 ` [PATCH V2 8/8] board: add Samsung specific board support Piotr Wilczek
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=20131218125203.GI4360@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).