C++ ifstream有奇数段错误,具体取决于文件在磁盘上的位置

phy*_*ael 0 c++ ifstream segmentation-fault

我有一些C++代码(使用ROOT库)我继承了(~1.5k行),我要做的第一件事就是解决一个与打开和读取二进制文件有关的错误运行时的参数.一些代表问题的代码如下所示:

[~/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
Run Code Online (Sandbox Code Playgroud)

因此,根据文件的位置,我成功打开并从文件中读取多个值会出现Seg Fault .报告的第175行只是常规inFile.read.

我很抱歉,如果没有实际的代码行,这可能很难提供帮助,但我认为我不能将代码最小化到一个说明它的小工作版本.有没有经历过这种事情的人?

Eri*_*rik 5

有人使用固定大小的缓冲区来处理文件名.查看解析argv的代码或记录文件名的代码.