Ale*_*lex 6 c++ strcat visual-c++
这是我的代码:
char sentence[ 100 ] = "";
char *article[ 5 ] = { "the", "a", "one", "some", "any" };
lexeme = rand() % 4; // random lexeme
strcat( sentence, article[ lexeme ] );
strcat( sentence, " " );
在MSVC++中调试时,它给了我这些警告消息:
Warning 1   warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead.
Warning 2   warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. 
我该如何解决?
Ste*_*end 15
这是因为没有什么可以阻止你 - strcat超过100个字节进入你的sentence缓冲区,未定义的结果包括堆损坏,堆栈损坏,程序退出,甚至有人拥有你的机器如果超过第100个字节的数据被适当地构造.这是一类常见的安全漏洞,称为缓冲区溢出.  
为了避免这种情况,请使用std::string's operator+,毕竟这是C++.CRT不再需要限制你.
| 归档时间: | 
 | 
| 查看次数: | 14385 次 | 
| 最近记录: |