This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ofstream crash with libstdc++


> It might be useful to enable exceptions[1] 

> on the stream and see if the open actually failed.
?
> Why not checking if fout.open() return NULL ?

I tried these methods:
1) 
??? std::string f="filter";
??? std::fstream fout;
??? fout.open(f.c_str(), std::fstream::app | std::fstream::out);
??? if (fout.is_open()) {
????? fout << "--------------------messages format--------------------------\n";? // STILL HAVE ERROR
??? }

2)
??? std::string f="filter";
??? fout.exceptions ( std::ofstream::failbit | std::ofstream::badbit );
??? try {
????? fout.open (f.c_str(), std::fstream::app | std::fstream::out);
????? fout << "--------------------messages format--------------------------\n";? // STILL HAVE ERROR
??? }
??? catch (std::ofstream::failure e) {
?? ? ? std::cout << "Exception opening/reading file";
??? }

In both cases the segmentation fault occurs at << operator.


>It's easier if you give code that actually demonstrates the crash than
>a snippet of code within some larger code.? At this point it's easier
>to assume that your code is at fault somehow.

The OS is scientific linux 6.3. To be honest, I run my code (without any change) on another scientific linux 6.0 and there is no problem. Also the source file is huge with other dependent libraries. 

In my system, gcc/g++ 4.4 are installed by default. I manually compiled gcc/g++4.1 and this code has been compiled with gcc/g++4.1. On another system (that is SL6.0 and the code works perfectly), only gcc/g++4.1 is installed and again the code has been compiled with gcc/g++4.1

I think there is a conflict between the what is compiled and the shared libraries at runtime. From the backtrace, I think it is saying that the functionality of '<<' that has been compiled is now different from what is read from a shared library. Not sure about that however....



Regards,
Mahmood



----- Original Message -----
From: Yann Droneaud <yann@droneaud.fr>
To: Mahmood Naderan <nt_mahmood@yahoo.com>
Cc: "libc-help@sourceware.org" <libc-help@sourceware.org>
Sent: Tuesday, February 19, 2013 2:51 PM
Subject: Re: ofstream crash with libstdc++

Hi,


> ??? .....
> ???? std::string f;
> ???? std::fstream
> fout;
> ???? f = "filter";
> ???? fout.open(f.c_str(), std::fstream::app | std::fstream::out);


Why not checking if fout.open() return NULL ?

Regards.

-- 
Yann Droneaud


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]