help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fstream.write() sigsegv's on cygwin


From: jeffsp
Subject: fstream.write() sigsegv's on cygwin
Date: 18 Feb 2005 16:39:54 -0800
User-agent: G2/0.2

When I compile the following program using g++ 3.4.3 and run it on a
windows 2000 machine under cygwin, I get a segmentation fault.

    #include <fstream>

    using namespace std;
    const unsigned N = 3000000;
    char a[N];

    int main ()
    {
        fstream fs ("temp.dat", ios::out | ios::binary);
        fs.write (&a[0], N);
        return 0;
    }

However, when I compile it with msvc 7.1 it works fine, and when I
compile it on a bsd machine using g++ 3.3 it also works fine.
Furthermore, if I change the data chunk size to be smaller, like 1M, it
works OK under cygwin.

Is the program not correct?

Here is a backtrace:

(gdb) run
Starting program: .../a.exe
Program received signal SIGSEGV, Segmentation fault.
0x610ec603 in cygwin1!_alloca () from /usr/bin/cygwin1.dll
(gdb) bt
#0  0x610ec603 in cygwin1!_alloca () from /usr/bin/cygwin1.dll
#1  0x61029f65 in cygwin_internal () from /usr/bin/cygwin1.dll
#2  0x6109ad7c in getppid () from /usr/bin/cygwin1.dll
#3  0x6108e1ef in cygwin1!aclcheck () from /usr/bin/cygwin1.dll
#4  0x0042e787 in std::basic_filebuf<char, std::char_traits<char>
>::xsputn (
    this=0x22ee7c, __s=0x441010 "", __n=3000000) at
.../gcc-3.4.3/i686-pc-cygwin/libstdc++-v3/include/bits/fstream.tcc:591
#5  0x00427044 in std::ostream::write (this=0x22ee78, __s=0x441010 "",
    __n=3000000)
    at .../gcc-3.4.3/i686-pc-cygwin/libstdc++-v3/include/streambuf:421
#6  0x00401221 in main () at temp.cpp:10

Also, if I step through the code, I find the following at the point
where it breaks:

----fstream.tcc----
590:    const char* __buf = reinterpret_cast<const
char*>(this->pbase());
591:    __ret = _M_file.xsputn_2(__buf, __buffill,
592:        reinterpret_cast<const char*>(__s), __n);
-------------------

where pbase() returns an invalid memory address during runtime (hence
the fault).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]