This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin 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]

Bug in fstream code and gcc-2 package?


The following example code works cleanly on all the platforms I've tested
on, except the gcc-2 package where it segfaults:

#include <fstream>
#include <string>

void load_file(std::string& s, std::istream& is)
{
s.erase();
if(is.bad()) return;
//
// attempt to grow string buffer to match file size,
// this doesn't always work...
s.reserve(is.rdbuf()->in_avail());
char c;
while(is.get(c))
{
// use logarithmic growth stategy, in case
// in_avail (above) returned zero:
if(s.capacity() == s.size())
s.reserve(s.capacity() * 3);
s.append(1, c);
}
}

int main()
{
std::string s;
std::ifstream ifs(__FILE__);
load_file(s, ifs);
return 0;
}


With:

$ g++-2 -v
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-10/specs
gcc version 2.95.3-10 (cygwin special)

gdb doesn't help much either:

$ gdb a.exe
GNU gdb 2003-09-20-cvs (cygwin-special)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-cygwin"...(no debugging symbols
found)...
(gdb) run
Starting program: /cygdrive/c/data/bugs/gcc/a.exe

Program received signal SIGSEGV, Segmentation fault.
0x2f09fe00 in ?? ()
(gdb) bt
#0  0x2f09fe00 in ?? ()
#1  0x00000400 in ?? ()
(gdb)

Thanks,

John Maddock




--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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