lkml.org 
[lkml]   [2010]   [Nov]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] Repalce strncmp by memcmp
From
Date
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



\
 
 \ /
  Last update: 2010-11-30 11:31    [W:0.057 / U:0.644 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site