【发布时间】:2019-12-24 11:02:01
【问题描述】:
我正在尝试通过 strlen() 函数将函数中的 2 个字符串复制到新的动态内存中。
char* PairSortedArrays(char a[], char b[])
{
char* p1 = (char*)malloc(strlen(a) + strlen(b) + 1);
if(p1)
{
strcpy(p1, a);
strcat(p1, b);
}
return p1;
}
得到编译器错误:
Severity Code Description Project File Line Suppression State
Error C4996 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. check C:\Users\97254\source\repos\check\check\Source.c 35
【问题讨论】:
-
我有错误 C4996 和 C6387
-
你没有检查
malloc()的返回值 -
我添加了 if(p1) 仍然有错误 C4496
-
您使用的是哪个编译器以及它的版本?
-
检查Why does Visual Studio 2013 error on C4996?。如果它可以解决你的问题。
标签: c