代码大致这样的
#include <stdio.h>
void fun2()
{
struct tt
{
int len;
char buf[];
};
struct tt t1;
strcpy(t1.buf, "123456...."); // 这里造成越界写
}
void fun1()
{
int i = 1;
fun2();
printf("i = %d\n", i); // 在开优化开 lto 的时候 i 的值会被 fun2 改变
}
我个人觉得这种情况应该是, 越界写改变栈的另外一个方向的内存啊, 不应该去改变上一层函数的变量啊. 还有为什么 valgrind 对这种情况一点都不吱声呢, 有什么工具能检查这种情况么?
谢谢