This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] C undefined behavior fix
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Linus Torvalds <torvalds at transmeta dot com>
- Cc: Richard Henderson <rth at redhat dot com>, Tom Rini <trini at kernel dot crashing dot org>, <gcc at gcc dot gnu dot org>
- Date: 06 Jan 2002 19:34:15 -0200
- Subject: Re: [PATCH] C undefined behavior fix
- Organization: GCC Team, Red Hat
- References: <Pine.LNX.4.33.0201041832410.1258-100000@penguin.transmeta.com>
On Jan 5, 2002, Linus Torvalds <torvalds@transmeta.com> 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 http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me