Bug 19478 - reading back from /dev/null
Summary: reading back from /dev/null
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.0.0
: P2 minor
Target Milestone: 4.0.1
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/fortran/2005-01...
Keywords: patch
Depends on:
Blocks: 19292
  Show dependency treegraph
 
Reported: 2005-01-17 10:52 UTC by Thomas Koenig
Modified: 2005-05-11 11:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-05-01 02:36:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2005-01-17 10:52:40 UTC
$ cat devnull-readback.f
      character*20 foo
      open(10,file="/dev/null")
      write(10,'(A)') "Hello"
      rewind(10)
      read(10,'(A)',end=100) foo
      print *,foo
      call abort
 100  continue
      end
$ gfortran devnull-readback.f
$ ./a.out
 Hello
Aborted
$ gfortran -v ; gfortran -dumpmachine
Using built-in specs.
Configured with: ../gcc-4.0-20050116/configure --prefix=/home/zfkts
--enable-languages=c,f95
Thread model: posix
gcc version 4.0.0 20050116 (experimental)
ia64-unknown-linux-gnu
$ g77 devnull-readback.f
$ ./a.out

Not really serious, but amusing :-)

        Thomas
Comment 1 Paul Thomas 2005-01-25 10:37:06 UTC
I do not believe this to be a bug:

An end-of-file condition occurs when no more records exist in a file during a 
sequential read, or when an end-of-file record produced by the ENDFILE statement
is encountered. End-of-file conditions do not occur in direct-access READ 
statements.

For A editting If w is equal to or greater than the length (len) of the input 
item, the rightmost characters are assigned to that item. The leftmost excess 
characters are ignored.

Adding a second read to the test program, generates the EOF condition a nd it 
is correctly trapped.
Comment 2 Thomas Koenig 2005-01-25 21:09:18 UTC
This may be legal according to the Fortran
standard (which knows nothing about /dev/null),
but it

1. breaks /dev/null semantics

2. viloates the principle of least surprise

3. is different from g77

4. is different from ifort

For reason 3, I've blocked 19292 with this.
Comment 3 Bud Davis 2005-01-30 15:24:48 UTC
proposed patch:

http://gcc.gnu.org/ml/fortran/2005-01/msg00329.html
Comment 4 Andrew Pinski 2005-01-30 15:30:47 UTC
Confirmed.
Comment 5 CVS Commits 2005-05-11 10:34:18 UTC
Subject: Bug 19478

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	fxcoudert@gcc.gnu.org	2005-05-11 10:34:06

Modified files:
	gcc/testsuite  : ChangeLog 
	libgfortran    : ChangeLog 
	libgfortran/io : unix.c 
Added files:
	gcc/testsuite/gfortran.dg: dev_null.f90 

Log message:
	PR fortran/19478
	* io/unix.c (fd_truncate): update positions when ftruncate
	fails (like writing to /dev/null).
	* gfortran.dg/dev_null.f90: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5465&r2=1.5466
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/dev_null.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.213&r2=1.214
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/io/unix.c.diff?cvsroot=gcc&r1=1.23&r2=1.24

Comment 6 CVS Commits 2005-05-11 10:39:56 UTC
Subject: Bug 19478

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	fxcoudert@gcc.gnu.org	2005-05-11 10:39:49

Modified files:
	gcc/testsuite  : ChangeLog 
	libgfortran    : ChangeLog 
	libgfortran/io : unix.c 
Added files:
	gcc/testsuite/gfortran.dg: dev_null.f90 

Log message:
	PR fortran/19478
	* io/unix.c (fd_truncate): update positions when ftruncate
	fails (like writing to /dev/null).
	* gfortran.dg/dev_null.f90: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.171&r2=1.5084.2.172
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/dev_null.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.163.2.27&r2=1.163.2.28
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/io/unix.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.21.10.2&r2=1.21.10.3

Comment 7 Andrew Pinski 2005-05-11 11:18:17 UTC
Fixed.