mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-21 11:16:16 +02:00
Add assertions.
This commit is contained in:
13
lib/memcpy.c
13
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;
|
||||
|
||||
Reference in New Issue
Block a user