可以对空指针使用strcpy_s吗?解决方案

可以对空指针使用strcpy_s吗?
char *str1=NULL;
str1=new char[20];
char str[7];
strcpy_s(str1,20,"hello world");  这个有错误吗
------解决思路----------------------
一点没问题,就是这么用,str1已经new了空间了,就是别忘了free
------解决思路----------------------
char *str1=NULL;
str1=new char[20];

str1已经=new char[20]了,已经分配内存空间了,就没问题。
str1已经不为空了,所以不叫“对空指针使用strcpy_s”
------解决思路----------------------
errno_t strcpy_s(
   char *strDestination,
   size_t numberOfElements,
   const char *strSource 
);

需要注意的是:
1,strDestination的空间要足够
2,strDestination与strSource重叠的话,行为未定义

如果strDestination=NULL,则该函数会返回EINVAL,表明什么都没做。

参考:
https://msdn.microsoft.com/en-us/library/td1esda9(VS.80).aspx