[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: MIT discovered issue with gcc

On Sun, Nov 24, 2013 at 12:18 AM, Robert Baron
<robertbartlettbaron@gmail.com> wrote:
> Second question:
> Doesn't memcpy allow for overlapping memory, but strcpy does not?  Isn't
> this why memcpy is preferred over strcpy?

The reason memcpy() is preferred over strcpy() is the same as the
reason strncpy() is preferred over strcpy().

memcpy() is actually considered a no-no in some circles, and perhaps
correctly so.  (Especially in C++, where classes are supposed to
define their own copying, and it's almost always more optimal to
explicitly copy each member instead of calculating the size, mass
copying, and going back and overwriting the members that are subject
to issues like deep copy. Remember that memcpy() is able to copy an
odd number of bytes, so the size calculation contains a bit more than
is obvious to the programmer.)

Joel Rees

Be careful where you see conspiracy.
Look first in your own heart.

Reply to: