我有一些C ++代码(使用ROOT库)我继承了(~1.5k行),我要做的第一件事就是解决与打开和阅读有关的bug一个二进制文件,在运行时作为参数传递。代表问题的一些代码如下所示:
[~/this]$ ./Make_RWQ_Tree /Users/me/this/that/mydata_f00000001.rwq
inFile: ./mydata_f00000001.rwq
outFile: ./mydata_f00000001.tru
Header Info:
a = 12
b = 345
c = 51
N = 100
G = 100
numEventsInFile = 1000
r = 1
s = 2
t = 4
*** Show info for each of the events in the file normally ***
[~/this]$
[~/this]$ mv ./mydata_f00000001.rwq /Users/me/this/that/another/directory/deeper/
[~/this]$ ./Make_RWQ_Tree /Users/me/this/that/another/directory/deeper/mydata_f00000001.rwq
inFile: ./mydata_f00000001.rwq
outFile: ./mydata_f00000001.tru
Header Info:
a = 12
b = 345
c = 51
N = 100
G = 100
numEventsInFile = 1000
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#5 0x00007fffffe007c5 in __memcpy ()
#6 0x00007fff87de59f7 in std::basic_streambuf<char, std::char_traits<char> >::xsgetn ()
#7 0x00007fff87dc7b19 in std::basic_filebuf<char, std::char_traits<char> >::xsgetn ()
#8 0x00007fff87dcd8c1 in std::istream::read ()
#9 0x0000000100001e25 in main (argc=<value temporarily unavailable, due to optimizations>, argv=<value temporarily unavailable, due to optimizations>) at Make_RWQ_Tree.cxx:175
因此,根据文件的位置,在成功打开并从文件中读取多个值后,我会收到Seg Fault 。报告的第175行只是常规inFile.read。
我很抱歉,如果没有实际的代码行,这可能很难提供帮助,但我认为我不能将代码最小化到一个说明它的小工作版本。有没有经历过这种事情的人?
答案 0 :(得分:5)
有人使用固定大小的缓冲区来处理文件名。查看解析argv的代码,或记录文件名的代码。