This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] C undefined behavior fix

On Jan  5, 2002, Linus Torvalds <> wrote:

> I think what people object to is optimizations that cannot be reasonably
> explained in any logical manner.

Err..  What's illogical in the following definition:

An expression such as:

  strcpy (to, "string literal" + offset)

where `"string literal" + offset' stands for an expression that can be
determined, at compile time, to be a pointer to the beginning of a
string literal not containing NULs, plus a (possibly negative) offset
that cannot be computed at compile time, is replaced with:

  memcpy (to, "string literal" + offset, sizeof "string literal" - offset)

Note: it is not necessary to verify that `offset' is in the interval
0..strlen("string literal"), because if it is not, undefined behavior
is invoked, since strcpy would dereference a pointer to memory outside
the object that was originally pointed to.

Alexandre Oliva   Enjoy Guarana', see
Red Hat GCC Developer                  aoliva@{,}
CS PhD student at IC-Unicamp        oliva@{,}
Free Software Evangelist    *Please* write to mailing lists, not to me

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]