I'm working on a fairly large program for a class, and now every time I run it, it segfaults. I've secluded the part that seems to cause the problems, and wrote a small file called test.cc, which contains a minimal implementation fo the code that brings up the segfault. It's attached. The code simply opens a file then reads it until empty. When I compile this with g++-3.3 (1:3.3.3-9), I get the following output from strace: open("test.cc", O_RDONLY) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=218, ...}) = 0 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40018000 read(3, "#include <fstream>\n\nusing namesp"..., 8192) = 218 read(3, "", 4096) = 0 --- SIGSEGV (Segmentation fault) @ 0 (0) --- +++ killed by SIGSEGV +++ I've opened and read files hundreds of times in my life. What gives now? -- Stephen Touset <stephen@touset.org>
#include <fstream> using namespace std; int main(void) { ifstream fin("test.cc"); char* str; if (!fin.is_open()) { exit(1); } while (!fin.eof()) { fin.getline(str, 80); } fin.close(); return 0; }
Attachment:
signature.asc
Description: This is a digitally signed message part