From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Haydn Grant To: gcc-gnats@gcc.gnu.org Subject: libstdc++/4442: bad fstream behavior Date: Tue, 02 Oct 2001 11:56:00 -0000 Message-id: <200110021847.OAA04090@localhost.localdomain> X-SW-Source: 2001-10/msg00015.html List-Id: >Number: 4442 >Category: libstdc++ >Synopsis: bad fstream behavior >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Tue Oct 02 11:56:01 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Andrew Haydn Grant >Release: 3.0.1 >Organization: >Environment: System: Linux Goof 2.2.14-5.0 #1 Tue Mar 7 21:07:39 EST 2000 i686 unknown Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: /usr/local/src/gcc-3.0.1/configure >Description: fstreams handle certain odd situations differently than they used to, causing old code to break. This code contains C++ less-than operators, so I don't know if the bug program will turn them into comment characters. void fail() { fstream f; f.close(); f.open("hello.txt", ios::in); char buffer[2048]; f.getline(buffer, 2048); cout << "FILE CONTENTS" << buffer << "FILE CONTENTS\n"; } The fail() function does not read "hello.txt". If you remove the initial f.close() call, it reads "hello.txt" without difficulty. void failWrite() { fstream f; f.open("/tmp/empire/simout.txt", ios::in); f.close(); f.open("/tmp/empire/simout.txt", ios::out); f << "It went out!!!\n"; } If the simout.txt file does NOT exist, the second open succeeds, but the << operator fails. If the simout file ALREADY exists, then all operations succeed. >How-To-Repeat: >Fix: To work around the problem, only use a given fstream object for one file operation. Avoid spurious close() calls. >Release-Note: >Audit-Trail: >Unformatted: