diff options
author | Jim Meyering <jim@meyering.net> | 1996-10-04 13:42:20 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1996-10-04 13:42:20 +0000 |
commit | 3400ffe3f22fa55d22be79288075a3de2238a6d1 (patch) | |
tree | 2f2d00c988fef593b216b9f7ae11fa91f9cc3e24 /lib | |
parent | fdd16fdb62455039c515eedbfea3c15b50465a23 (diff) | |
download | coreutils-3400ffe3f22fa55d22be79288075a3de2238a6d1.tar.xz |
Add assertions.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/memcpy.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/memcpy.c b/lib/memcpy.c index dba7d56f1..aec71e36b 100644 --- a/lib/memcpy.c +++ b/lib/memcpy.c @@ -2,6 +2,15 @@ if the source overlaps with the destination. Return DESTADDR. */ +#include <assert.h> + +/* FIXME: uncomment the following for releases. */ +#define NDEBUG 1 + +#ifndef ABS +# define ABS(x) ((x) < 0 ? (-(x)) : (x)) +#endif + char * memcpy (destaddr, srcaddr, len) char *destaddr; @@ -10,6 +19,10 @@ memcpy (destaddr, srcaddr, len) { char *dest = destaddr; + assert (len >= 0); + /* Make sure they don't overlap. */ + assert (ABS (destaddr - srcaddr) >= len); + while (len-- > 0) *destaddr++ = *srcaddr++; return dest; |