Re: [Linux-ia64] Re: memcpy failure

From: Matthew Wilcox <>
Date: 2002-11-16 01:17:55
On Fri, Nov 15, 2002 at 02:51:36PM +0100, Christian Cotte-Barrot wrote:
> Matthew Wilcox wrote:
> > _what_ bad return from memcpy?!  memcpy returns the pointer that was
> > passed to it.  What are you going to check for?
> > 
> Simply, bad return is whatever is not equal to the dest pointer:
>   if ((memcpy(rptr, ch->rxptr + tail, dataToRead)) != rptr)
>     ...

No.  You don't get it.  memcpy returns the pointer that was passed in.
Nothing more, nothing less.  There is no `error return'.  There is no
`what if'.  memcpy is defined to succeed.  Look:

" The memcpy function

#include <string.h>
void *memcpy(void * restrict s1, const void * restrict s2, size_t n);

The memcpy function copies n characters from the object pointed to by s2
into the object pointed to by s1. If copying takes place between objects
that overlap, the behavior is undefined.

The memcpy function returns the value of s1.

Testing the result of memcpy is bad C.  Don't ever do it.

Revolutions do not require corporate support.
Received on Fri Nov 15 06:18:00 2002

This archive was generated by hypermail 2.1.8 : 2005-08-02 09:20:11 EST