[lkml]   [2002]   [Jan]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH] C undefined behavior fix
>>>>> "Jakub" == Jakub Jelinek <> writes:

Jakub> On Wed, Jan 02, 2002 at 08:39:20AM -0700, Tom Rini wrote:
>> Well, Paulus wrote 'strcpy' not 'memcpy', so why does gcc get to
>> assume it's safe to change it? In this case it's certainly not.

Jakub> But unless you trigger undefined behaviour, strcpy(x, "foobar"
Jakub> + n) is equal to memcpy(x, "foobar" + n, sizeof("foobar") -
Jakub> n); and the latter is more efficient (you don't have to check
Jakub> for end-of-string during copying).

I'd say it's the same even if you DO trigger undefined behavior.

"Undefined" means "anything can happen, don't blame the compiler". In
particular, different things may happen at different times, under
different compilers, under different phases of the moon, etc...

The change from strcpy to memcpy either replaces a defined action by
the equivalent one, or replaces an undefined action by an undefined
action. In the undefined case, the outcome may be different after the
change, but that's perfectly ok, that's what "undefined" means.

It might be interesting for the compiler to warn about this coding
error (since it presumably can detect it). But "fixing" the behavior
of undefined code seems like a strange thing to do.


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:15    [W:0.076 / U:3.068 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site