It seems wofstream and wostream get trouble when a L'\0' character is entered
into the middle of their buffer. wofstream generates a Segmentation fault when
flushing the buffer.

This is a very simple report so I just the source code here:

--* source *--

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    wofstream ff("tt", ios_base::binary);
    ff<<L'A';
    ff<<L'\0';
    ff<<L'B';
    cout<<"Still okay..."<<endl;
}

--* end source *--

Compile command: g++ -g test.C

--* output *--
prompt> a.out
Still okay...
Segmentation fault

--* end output *--

--* gdb *--

Starting program: /epp/home/phyfai/C-repository/utility/a.out

Breakpoint 1, main () at test.C:8
8           ff<<L'A';
(gdb) s
s9          ff<<L'\0';
(gdb) s
10          ff<<L'B';
(gdb) s
11          cout<<"Still okay..."<<endl;
(gdb) s
Still okay...

Program received signal SIGSEGV, Segmentation fault.
0x401999da in wcsnlen () from /lib/tls/libc.so.6
(gdb) s
Single stepping until exit from function wcsnlen,
which has no line number information.

Program terminated with signal SIGSEGV, Segmentation fault.

--* end gdb *--

I guess, at some point during conversion to external encoding, wcsnlen() is
called, and determine '\0' in buffer as end trigger some memory problem. wcout
doesn't generate segmentation fault, but stop displaying when it encounters a
L'\0'. ofstream and cout doesn't have this problem.

-- 
           Summary: Segmentation fault using wofstream
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: phyfai at physics dot unimelb dot edu dot au
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18780

Reply via email to