我以某种方式破坏了内存,因为我的程序在随机位置崩溃而没有错误。

我将valgrind与--leak-check=full结合使用,并与-O0 -g一起编译,并且它检测到的第一个问题是int main()中的第一行

cout << "reading file" << endl;


==5089== Warning: client switching stacks?  SP change: 0x7ff0004f8 --> 0x7feb7de10
==5089==          to suppress, use: --max-stackframe=4728552 or greater
==5089== Invalid write of size 8
==5089==    at 0x41E107: main (Dgn.cpp:2833)
==5089==  Address 0x7feb7de08 is on thread 1's stack

它继续
==5089== Invalid read of size 8
==5089==    at 0x5DE6E10: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.18)
==5089==    by 0x67AEDE4: (below main) (libc-start.c:260)
==5089==  Address 0x7feb7de08 is on thread 1's stack
==5089==
==5089== Invalid write of size 8
==5089==    at 0x5DBF8F2: std::ios_base::ios_base() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.18)
==5089==    by 0x5E06BFF: std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(char const*, std::_Ios_Openmode) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.18)
==5089==    by 0x41E131: main (Dgn.cpp:2834)
==5089==  Address 0x7feb7e1e8 is on thread 1's stack

指向
ifstream config_file("file");

几乎每一行都有错误。

是什么原因造成的?

最佳答案

我想我炸了我的第一叠!

here



减小尺寸可以解决此问题。

09-10 01:31