Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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" To: Subject: Bug in fstream code and gcc-2 package? Date: Fri, 2 Jan 2004 12:54:34 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit The following example code works cleanly on all the platforms I've tested on, except the gcc-2 package where it segfaults: #include #include 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/