libstdc++/4442: bad fstream behavior <synopsis of the problem (one line)>
Andrew Haydn Grant
haydn@localhost.localdomain
Tue Oct 2 11:56:00 GMT 2001
>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:
More information about the Gcc-prs
mailing list