delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/01/02/07:55:11

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <02ca01c3d12f$99abb120$b9510352@fuji>
From: "John Maddock" <john AT johnmaddock DOT co DOT uk>
To: <cygwin AT cygwin DOT com>
Subject: Bug in fstream code and gcc-2 package?
Date: Fri, 2 Jan 2004 12:54:34 -0000
MIME-Version: 1.0

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019