【发布时间】:2012-04-12 17:40:04
【问题描述】:
可能重复:
Why does this intentionally incorrect use of strcpy not fail horribly?
如下代码:
char* stuff = (char*)malloc(2);
strcpy(stuff,"abc");
cout<<"The size of stuff is : "<<strlen(stuff);
即使我为东西分配了 2 个字节,为什么 strcpy 仍然可以工作,而 strlen 的输出是 3。这不应该抛出诸如 index out of bounds 之类的东西吗?
【问题讨论】:
-
这就是伟大的“缓冲区溢出!!”的原因:P