memcpy, memmove with NULL pointers?

J

Jef Driesen

Hi,

Is it safe to pass a NULL pointer to the memcpy, memmove functions (and
other similar ones) if the size parameter is zero?

memcpy (dest, NULL, 0);

Or is that implementation defined and do I explicitly have to check for
this condition?

Thanks,

Jef
 
E

Erik Trulsson

Jef Driesen said:
Hi,

Is it safe to pass a NULL pointer to the memcpy, memmove functions (and
other similar ones) if the size parameter is zero?

memcpy (dest, NULL, 0);

No, it is not safe. You need to pass valid pointers even if the size is zero.

Or is that implementation defined and do I explicitly have to check for
this condition?

It is not even implementation defined - it is undefined behaviour.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top