better code
Posted May 31, 2003 1:39 UTC (Sat) by
dododge (subscriber, #2870)
In reply to:
better code by tjc
Parent article:
strlcpy()
/* check for overlapping source and destination */
if ((src < dest && src + len >= dest)
Pointer comparison is undefined if the pointers
are not within the same object, so this is not
portable standard C.
memmove is safe for overlapping regions,
and since it's part of the standard library it's
allowed to use
architecture-specific magic to compare arbitrary
pointers. It can also make use of optimized machine
code, so it's potentially more efficient than any
implementation written in standard C.
but I've found that the best way to debug code is to post it on the internet.
I haven't looked closely at the rest of the function. If you
want it thoroughly picked apart you could try posting it to
USENET comp.lang.c [insert evil laugh] :-)
(
Log in to post comments)