public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/35132]  New: Formatted stream I/O write should truncate
@ 2008-02-07 22:32 tkoenig at gcc dot gnu dot org
  2008-02-07 22:52 ` [Bug libfortran/35132] " burnus at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-02-07 22:32 UTC (permalink / raw)
  To: gcc-bugs

>From c.l.f, Richard Maine:

2003 9.2.3.3, "File position after data
transfer", 3rd para

  "For a formatted stream output statement, if no error condition
occurred, the terminall point of the file is set to the highest-numbered
position to which data was transferred by the statement."

Currently, we don't.  The following program shouldn't work:

program main
  implicit none
  character(len=6) :: c
  integer :: i
  open(20,file="foo.txt",form="formatted",access="stream")
  write(20,'(A)') '123456'
  write(20,'(A)') 'abcdef'
  write(20,'(A)') 'qwerty'
  rewind 20
  ! Skip over the first line
  read(20,'(A)') c
  ! Save the position
  inquire(20,pos=i)
  ! Read in the complete line...
  read(20,'(A)') c
  ! Write out the first four characters
  write(20,'(A)',pos=i,advance="no") 'ASDF'
  ! Fill up the rest of the line.  Here, we know the length.  If we
  ! don't, things will be a bit more complicated.
  write(20,'(A)') c(5:6)
  ! Copy the file to standard output
  rewind 20
  do i=1,3
    read(20,'(A)') c
    print '(A)',c
  end do
  close (20)
end program main

It currently prints

123456
ASDFef
qwerty

which is wrong.


-- 
           Summary: Formatted stream I/O write should truncate
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35132


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libfortran/35132] Formatted stream I/O write should truncate
  2008-02-07 22:32 [Bug libfortran/35132] New: Formatted stream I/O write should truncate tkoenig at gcc dot gnu dot org
@ 2008-02-07 22:52 ` burnus at gcc dot gnu dot org
  2008-02-08 20:48 ` jvdelisle at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-02-07 22:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2008-02-07 22:52 -------
See:
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/9e38ff2694bfdab1/

If I understand it correctly, the right solution is do the same as NAG f95 does
and print the following:

123456
ASDFef
End of file on unit 20
Program terminated by I/O error on unit 20 (File="foo.txt",Formatted,Stream)

With the file "foo.txt" containing two lines.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2008-02-07 22:52:03
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35132


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libfortran/35132] Formatted stream I/O write should truncate
  2008-02-07 22:32 [Bug libfortran/35132] New: Formatted stream I/O write should truncate tkoenig at gcc dot gnu dot org
  2008-02-07 22:52 ` [Bug libfortran/35132] " burnus at gcc dot gnu dot org
@ 2008-02-08 20:48 ` jvdelisle at gcc dot gnu dot org
  2008-02-08 21:41 ` jvdelisle at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-02-08 20:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jvdelisle at gcc dot gnu dot org  2008-02-08 20:47 -------
I will take this one.


-- 

jvdelisle at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jvdelisle at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2008-02-07 22:52:03         |2008-02-08 20:47:47
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35132


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libfortran/35132] Formatted stream I/O write should truncate
  2008-02-07 22:32 [Bug libfortran/35132] New: Formatted stream I/O write should truncate tkoenig at gcc dot gnu dot org
  2008-02-07 22:52 ` [Bug libfortran/35132] " burnus at gcc dot gnu dot org
  2008-02-08 20:48 ` jvdelisle at gcc dot gnu dot org
@ 2008-02-08 21:41 ` jvdelisle at gcc dot gnu dot org
  2008-02-09 21:49 ` tkoenig at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-02-08 21:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jvdelisle at gcc dot gnu dot org  2008-02-08 21:40 -------
How does this look  :)  I have a couple of other test prints in there.

$ gfc pr35132.f90 
$ ./a.out
 1st: 123456
 2nd: abcdef
123456
ASDFef
At line 26 of file pr35132.f90 (unit = 20, file = 'foo.txt')
Fortran runtime error: End of file


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35132


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libfortran/35132] Formatted stream I/O write should truncate
  2008-02-07 22:32 [Bug libfortran/35132] New: Formatted stream I/O write should truncate tkoenig at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2008-02-08 21:41 ` jvdelisle at gcc dot gnu dot org
@ 2008-02-09 21:49 ` tkoenig at gcc dot gnu dot org
  2008-02-10 11:43 ` tkoenig at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-02-09 21:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from tkoenig at gcc dot gnu dot org  2008-02-09 21:48 -------
(In reply to comment #3)
> How does this look  :)  I have a couple of other test prints in there.
> 
> $ gfc pr35132.f90 
> $ ./a.out
>  1st: 123456
>  2nd: abcdef
> 123456
> ASDFef
> At line 26 of file pr35132.f90 (unit = 20, file = 'foo.txt')
> Fortran runtime error: End of file

This is looking very good, it is the correct behavior.

When do you plan to submit?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35132


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libfortran/35132] Formatted stream I/O write should truncate
  2008-02-07 22:32 [Bug libfortran/35132] New: Formatted stream I/O write should truncate tkoenig at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2008-02-09 21:49 ` tkoenig at gcc dot gnu dot org
@ 2008-02-10 11:43 ` tkoenig at gcc dot gnu dot org
  2008-02-10 13:52 ` jvdelisle at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-02-10 11:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from tkoenig at gcc dot gnu dot org  2008-02-10 11:43 -------
Hi Jerry,

_unformatted_ stream should not truncate, you can
put bytes into the middle of a file there.

Does your patch do that?  (I can't test right now).

Thomas


-- 

tkoenig at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jvdelisle at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35132


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libfortran/35132] Formatted stream I/O write should truncate
  2008-02-07 22:32 [Bug libfortran/35132] New: Formatted stream I/O write should truncate tkoenig at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2008-02-10 11:43 ` tkoenig at gcc dot gnu dot org
@ 2008-02-10 13:52 ` jvdelisle at gcc dot gnu dot org
  2008-02-17 10:11 ` tkoenig at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-02-10 13:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jvdelisle at gcc dot gnu dot org  2008-02-10 13:51 -------
The patch only touches on formatted stream io:

    case FORMATTED_STREAM:
    case FORMATTED_SEQUENTIAL:
---snip---
          if (is_stream_io (dtp))
            {
              dtp->u.p.current_unit->strm_pos += len;
              struncate(dtp->u.p.current_unit->s);
            }


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35132


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libfortran/35132] Formatted stream I/O write should truncate
  2008-02-07 22:32 [Bug libfortran/35132] New: Formatted stream I/O write should truncate tkoenig at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2008-02-10 13:52 ` jvdelisle at gcc dot gnu dot org
@ 2008-02-17 10:11 ` tkoenig at gcc dot gnu dot org
  2008-02-21  2:28 ` jvdelisle at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2008-02-17 10:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from tkoenig at gcc dot gnu dot org  2008-02-17 10:11 -------
Patch has been OK'd for 4.4.


-- 

tkoenig at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |http://gcc.gnu.org/ml/fortra
                   |                            |n/2008-02/msg00077.html
           Keywords|                            |patch
   Target Milestone|---                         |4.4.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35132


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libfortran/35132] Formatted stream I/O write should truncate
  2008-02-07 22:32 [Bug libfortran/35132] New: Formatted stream I/O write should truncate tkoenig at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2008-02-17 10:11 ` tkoenig at gcc dot gnu dot org
@ 2008-02-21  2:28 ` jvdelisle at gcc dot gnu dot org
  2008-02-21  2:35 ` jvdelisle at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-02-21  2:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jvdelisle at gcc dot gnu dot org  2008-02-21 02:27 -------
Subject: Bug 35132

Author: jvdelisle
Date: Thu Feb 21 02:27:07 2008
New Revision: 132512

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132512
Log:
2008-02-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

        PR libfortran/35132
        * io/transfer.c (next_record_w): Truncate after the last record for
        STREAM I/O.

        PR libfortran/34954
        * io/transfer.c (data_transfer_init): Initialize dtp->rec if writing.

        PR libfortran/34974
        * io/transfer.c (formatted_transfer_scalar): Flush the buffer if skips
        is less than zero. (next_record_w): Use sseek to position the file to
        the max position reached.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/transfer.c


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35132


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libfortran/35132] Formatted stream I/O write should truncate
  2008-02-07 22:32 [Bug libfortran/35132] New: Formatted stream I/O write should truncate tkoenig at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2008-02-21  2:28 ` jvdelisle at gcc dot gnu dot org
@ 2008-02-21  2:35 ` jvdelisle at gcc dot gnu dot org
  2008-02-21  2:46 ` jvdelisle at gcc dot gnu dot org
  2008-02-21  2:54 ` jvdelisle at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-02-21  2:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jvdelisle at gcc dot gnu dot org  2008-02-21 02:34 -------
Subject: Bug 35132

Author: jvdelisle
Date: Thu Feb 21 02:33:17 2008
New Revision: 132513

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132513
Log:
2008-02-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

        PR libfortran/34974
        * gfortran.dg/fmt_t_7.f: New test.

        PR libfortran/35132
        * gfortran.dg/streamio_15.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/fmt_t_7.f
    trunk/gcc/testsuite/gfortran.dg/streamio_15.f90
Modified:
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35132


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libfortran/35132] Formatted stream I/O write should truncate
  2008-02-07 22:32 [Bug libfortran/35132] New: Formatted stream I/O write should truncate tkoenig at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2008-02-21  2:35 ` jvdelisle at gcc dot gnu dot org
@ 2008-02-21  2:46 ` jvdelisle at gcc dot gnu dot org
  2008-02-21  2:54 ` jvdelisle at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-02-21  2:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from jvdelisle at gcc dot gnu dot org  2008-02-21 02:46 -------
Fixed on trunk.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35132


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug libfortran/35132] Formatted stream I/O write should truncate
  2008-02-07 22:32 [Bug libfortran/35132] New: Formatted stream I/O write should truncate tkoenig at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2008-02-21  2:46 ` jvdelisle at gcc dot gnu dot org
@ 2008-02-21  2:54 ` jvdelisle at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-02-21  2:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from jvdelisle at gcc dot gnu dot org  2008-02-21 02:54 -------
Closing


-- 

jvdelisle at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35132


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-02-21  2:54 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-07 22:32 [Bug libfortran/35132] New: Formatted stream I/O write should truncate tkoenig at gcc dot gnu dot org
2008-02-07 22:52 ` [Bug libfortran/35132] " burnus at gcc dot gnu dot org
2008-02-08 20:48 ` jvdelisle at gcc dot gnu dot org
2008-02-08 21:41 ` jvdelisle at gcc dot gnu dot org
2008-02-09 21:49 ` tkoenig at gcc dot gnu dot org
2008-02-10 11:43 ` tkoenig at gcc dot gnu dot org
2008-02-10 13:52 ` jvdelisle at gcc dot gnu dot org
2008-02-17 10:11 ` tkoenig at gcc dot gnu dot org
2008-02-21  2:28 ` jvdelisle at gcc dot gnu dot org
2008-02-21  2:35 ` jvdelisle at gcc dot gnu dot org
2008-02-21  2:46 ` jvdelisle at gcc dot gnu dot org
2008-02-21  2:54 ` jvdelisle at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).