Mercurial > hg > octave-nkf > gnulib-hg
changeset 708:fd8fe79702e0
Add assertions.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Fri, 04 Oct 1996 13:42:20 +0000 |
parents | 52cd746c10f6 |
children | 55597eae039e |
files | lib/memcpy.c |
diffstat | 1 files changed, 13 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ { char *dest = destaddr; + assert (len >= 0); + /* Make sure they don't overlap. */ + assert (ABS (destaddr - srcaddr) >= len); + while (len-- > 0) *destaddr++ = *srcaddr++; return dest;