Subject: Re: Performance of various memcpy()'s
To: Perry E. Metzger <perry@piermont.com>
From: Bang Jun-Young <junyoung@mogua.com>
List: tech-userlevel
Date: 10/30/2002 02:38:20
On Tue, Oct 29, 2002 at 12:10:58PM -0500, Perry E. Metzger wrote:
> 
> Bang Jun-Young <junyoung@mogua.com> writes:
> > Along with this change, I'd like to get rid of _DIAGNOSTIC stuff as well.
> > I don't understand why there's such a pointer wraparound check, since
> > the memcpy(3) clearily says "use memmove() for overlap case." It might
> > be worth adding "if you're not sure, always use memmove()." comment
> > to memcpy(3).
> 
> We put stuff like that in place so that people can catch bugs, like
> using memcpy if you meant memmove. Believe it or not, people do make
> mistakes. It is reasonable to want to have bug-detection mechanisms
> available for those who want them.

First, the pointer wraparound check can only catch a rare bug. Second,
even if it can, it's still not very helpful in most cases. If memcpy was
called with wrong argument, program would die with a seg fault. If memcpy
returned with an error because of the wraparound check, the program would
still die, since normal program would never call memcpy with length of
0xffffffff. Something must be wrong in other part of the program. This
way you can't find what caused it. It'd be better to just examine a core.

Anyway, TAMURA Kent, who wrote the check code, agreed on that, and I 
removed it from the source.

Jun-Young

-- 
Bang Jun-Young <junyoung@mogua.com>