On 2017-02-20, Steffen Nurpmeso <stef...@sdaoden.eu> wrote: > Hey, > > Just something funny for in between... > I am now looking over all calls to memcpy() because i got a crash > on OpenBSD on a perfect subject to memcpy(), effectively a string > move forward (i.e., leftwise). I never would have even thought on > anything else but > > // the difference to Copy is that this fn handles overlapping regions, > // i.e., starts at the end if source (_from) LT destination (_to). > // so what we do is easy and thus we just jump off to copy unless we > // can't. this works because the functions use equal stacks and so. > > so that i became a hundred percent used to that. Yes, now i read > that the standard says "If copying takes place between objects > that overlap, the behavior is undefined", but they don't overlap, > do they -- you have to load before you store. > Have a good night. > > --steffen > >
Better to have a clear crash with good diagnostics than something which may work in some circumstnaces and fail horribly in others (there was a particularly fun thing five or so years ago when glibc had a different implementation of memcpy that didn't handle overlaps and used it on certain intel CPUs).