public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Bernd Petrovitsch <bernd@petrovitsch.priv.at>
To: Ryan Mallon <ryan@bluewatersys.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	pavel@pavlinux.ru, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Repalce strncmp by memcmp
Date: Tue, 30 Nov 2010 11:27:51 +0100	[thread overview]
Message-ID: <1291112871.16068.7.camel@thorin> (raw)
In-Reply-To: <4CF42E5A.7000709@bluewatersys.com>

On Die, 2010-11-30 at 11:51 +1300, Ryan Mallon wrote:
[...] 
> It can still break things in subtle ways. Lots of the replacements are
> of the form:
> 
>   if (strncmp(string, "foo", 3) == 0)
> 
> Which can only be replaced with memcmp if the minimum length of string
> is _always_ 3. This may be true for some callsites (with careful audit),
> but in general I doubt it is and it will lead to subtle bugs.
> 
> I hardly think it is worth auditing a bunch of strncmp calls to ensure
> that the minimum length of the checked string is always n in order to
> remove a single instruction. Making such a change will also introduce
> subtle bugs if the rules for the string ever change, eg. a change is
> made to allow string = "".

On the conceptual level:
And it will confuse people if strings (read: '\0' terminated char arrays
specified by a pointer to the start) with raw memory (read: memory with
arbitrary content - including '\0' not at the end - specified by a
pointer to the start and the valid size).
Even more confusing is that raw memory *may* hold a string ...

Don't get me wrong: every seasoned C programmer should know that. But
not everyone is one ...

Bernd
-- 
Bernd Petrovitsch                  Email : bernd@petrovitsch.priv.at
                     LUGA : http://www.luga.at


  reply	other threads:[~2010-11-30 10:28 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-29  2:09 [PATCH] Repalce strncmp by memcmp Pavel Vasilyev
2010-11-29  2:21 ` microcai
2010-11-29  2:29 ` Ming Lei
2010-11-29  3:11   ` Pavel Vasilyev
2010-11-29  4:13     ` Dmitry Torokhov
2010-11-29  5:26       ` YOSHIFUJI Hideaki
2010-11-29 12:41         ` Pavel Vasilyev
2010-11-29  3:10 ` Américo Wang
2010-11-29 10:18 ` Andi Kleen
2010-11-29 14:58 ` Steven Rostedt
2010-11-29 19:41   ` Pavel Vasilyev
2010-11-29 22:18     ` Steven Rostedt
2010-11-29 22:26       ` Steven Rostedt
2010-11-29 22:49         ` Pavel Vasilyev
2010-11-30  9:24           ` Américo Wang
2010-11-29 22:51         ` Ryan Mallon
2010-11-30 10:27           ` Bernd Petrovitsch [this message]
2010-11-29 23:32 ` Arnaud Lacombe
2010-11-30 10:34 ` Bernd Petrovitsch

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=1291112871.16068.7.camel@thorin \
    --to=bernd@petrovitsch.priv.at \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@pavlinux.ru \
    --cc=rostedt@goodmis.org \
    --cc=ryan@bluewatersys.com \
    /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