[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1291112871.16068.7.camel@thorin>
Date: Tue, 30 Nov 2010 11:27:51 +0100
From: Bernd Petrovitsch <bernd@...rovitsch.priv.at>
To: Ryan Mallon <ryan@...ewatersys.com>
Cc: Steven Rostedt <rostedt@...dmis.org>, pavel@...linux.ru,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] Repalce strncmp by memcmp
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@...rovitsch.priv.at
LUGA : http://www.luga.at
--
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