From 3400ffe3f22fa55d22be79288075a3de2238a6d1 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Fri, 4 Oct 1996 13:42:20 +0000 Subject: Add assertions. --- lib/memcpy.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 + +/* 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; -- cgit v1.2.3-70-g09d2