This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

libstdc++/6750: ofstream incorrectly sets failbit (severe regression)



>Number:         6750
>Category:       libstdc++
>Synopsis:       ofstream incorrectly sets failbit (severe regression)
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 20 13:36:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Peter Schmid
>Release:        3.1.1 20020519 (prerelease)
>Organization:
TU Darmstadt
>Environment:
System: Linux kiste 2.4.18 #8 Sat Mar 9 15:33:15 CET 2002 i686 unknown
Architecture: i686
SuSE 7.3
binutils 20020428
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --enable-shared --disable-nls --enable-threads=posix --enable-languages=c,c++,f77,objc
>Description:
Today I encountered a severe regression on the branch. When I ran the
following program tio, compiled by gcc 3.1 20020519, the contents of
the file tio.dat is truncated. When I type a carriage return on the
keyboard as input for the second getline call the output
file stream sets erroneously the fail bit when written to. The
following writes are missing from the output file. This is a severe
regression from gcc 2.95.3. 

I makes no difference whether the input is read from a file via file
descriptor redirection or typed on the keyboard.

>How-To-Repeat:
source code tio.C

#include <iostream>
#include <fstream>

#define OUTPUT_FILE	"tio.dat"
#define BUFFSIZ		2048

int main()
{
  using namespace std; 
  char buff[BUFFSIZ];

  ofstream output(OUTPUT_FILE, ios::out);
  if(!output) {
    cerr << "Cannot create " << OUTPUT_FILE << endl;
    exit(1);
  }
  cout << "Output file will be '" << OUTPUT_FILE << "'." << endl;

  cout<<"rdstate before reading from cin: "
      << cin.rdstate() << endl;
  cout<<"good eof fail bad "
      << ios::goodbit << " "
      << ios::eofbit << " "
      << ios::failbit << " "
      << ios::badbit << endl;
	
  cout << "Enter line 1 of 3: ";
  cin.getline(buff, BUFFSIZ);
  output << buff << endl;
  cerr << "cin state: " << cin.rdstate() << endl;
  cerr << "output state: " << output.rdstate() << endl;

  cout << "Enter line 2 of 3: ";
  cin.getline(buff, BUFFSIZ);					       
  output << buff << endl;
  cerr << "cin state: " << cin.rdstate() << endl;
  cerr << "output state: " << output.rdstate() << endl;

  cout << "Enter line 3 of 3: ";
  cin.getline(buff, BUFFSIZ);
  output << buff << endl;
  cerr << "cin state: " << cin.rdstate() << endl;
  cerr << "output state: " << output.rdstate() << endl;
}

g++ -v -o tio tio.C -W -Wall 
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/specs
Configured with: ../gcc/configure --enable-shared --disable-nls --enable-threads=posix --enable-languages=c,c++,f77,objc
Thread model: posix
gcc version 3.1.1 20020519 (prerelease)
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=1 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ tio.C -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -quiet -dumpbase tio.C -W -Wall -version -o /tmp/ccQLkRS9.s
GNU CPP version 3.1.1 20020519 (prerelease) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.1.1 20020519 (prerelease) (i686-pc-linux-gnu)
	compiled by GNU C version 3.1.1 20020519 (prerelease).
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory "/usr/local/i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/g++-v3
 /usr/local/include/g++-v3/i686-pc-linux-gnu
 /usr/local/include/g++-v3/backward
 /usr/local/include
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/../../../../i686-pc-linux-gnu/bin/as -V -Qy -o /tmp/ccSA70i7.o /tmp/ccQLkRS9.s
GNU assembler version 020428 (i686-pc-linux-gnu) using BFD version 020428 20020428
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o tio /usr/lib/crt1.o /usr/lib/crti.o /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/crtbegin.o -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1 -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/../../../../i686-pc-linux-gnu/lib -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/../../.. /tmp/ccSA70i7.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/crtend.o /usr/lib/crtn.o

gcc 3.1
./tio
Output file will be 'tio.dat'.
rdstate before reading from cin: 0
good eof fail bad 0 2 4 1
Enter line 1 of 3: Hallo
cin state: 0
output state: 0
Enter line 2 of 3: //return key pressed
cin state: 0
output state: 1
Enter line 3 of 3: Peter!
cin state: 0
output state: 1

cat tio.dat
Hallo

gcc 2.95.3

./tio
Output file will be 'tio.dat'.
rdstate before reading from cin: 0
good eof fail bad 0 1 2 4
Enter line 1 of 3: Hallo
cin state: 0
output state: 0
Enter line 2 of 3: 
cin state: 0
output state: 0
Enter line 3 of 3: Peter!
cin state: 0
output state: 0

cat tio.dat
Hallo

Peter!

>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:


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