c++language-lawyermemcpy

"memcpy must be given valid pointers": where can I find this in the standard?


It is stated on cppref that

If either dest or src is an invalid or null pointer, the behavior is undefined, even if count is zero

Same is stated for memset and memmove.

My question is: where is it stated in the standard? I need to justify this as an UB to my client, but a link to a cppref article won' t do, I need the reference in the standard.

Public draft of the standard


Solution

  • The C++ standard refers the C standard, and these functions are defined in the C standard.

    7.24 String handling <string.h>

    7.24.1 String function conventions

    1. <...> Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4. <...>

    7.1.4 Use of library functions

    1. <...> If an argument to a function has an invalid value (such as a value outside the domain of the function, or a pointer outside the address space of the program, or a null pointer, or a pointer to non-modifiable storage when the corresponding parameter is not const-qualified) or a type (after promotion) not expected by a function with variable number of arguments, the behavior is undefined <...>

    C17 ISO/IEC 9899:2018 N2310