Bug 34974 - null bytes when reverse-tabbing long records (regression vs. g77)
Summary: null bytes when reverse-tabbing long records (regression vs. g77)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 4.4.0
Assignee: Jerry DeLisle
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-01-25 19:29 UTC by Thomas Koenig
Modified: 2008-05-16 03:12 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-02-13 05:48:29


Attachments
Tentative patch (536 bytes, patch)
2008-02-14 06:00 UTC, Jerry DeLisle
Details | Diff
Revised patch (524 bytes, patch)
2008-02-15 04:18 UTC, Jerry DeLisle
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2008-01-25 19:29:33 UTC
$ cat tab.f
       program main
       write (*,'(t1000000,a,t1,a)') 'b', 'a'
       end
$ gfortran tab.f
$ ./a.out > foo.dat
$ od -a -N32 foo.dat
0000000   a nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
0000020 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
0000040
Comment 1 Thomas Koenig 2008-01-25 19:35:02 UTC
Actually, it's "null bytes" :-)

This is related to PR 34887.

The problem here is that we tab further than our buffer size,
so we write out garbage.

Ceterum censeo stream I/O esse delendam :-)
Comment 2 Jerry DeLisle 2008-01-26 16:22:40 UTC
The problem first occurs at the 8192 boundary at which point we do not write "b"

       program main
       write (10,'(t8193,a,t1,a)') 'b', 'a'
       end

Comment 3 Jerry DeLisle 2008-01-26 16:23:08 UTC
Confirming
Comment 4 Thomas Koenig 2008-01-26 19:43:49 UTC
This one is tricky.

The problem occurs because of buffering.  When tabbing to
8193 in Jerry's example, we come to the end of the
buffer and flush it.

When the record is longer than the buffer length, we'll
need to extend the buffer.
Comment 5 Jerry DeLisle 2008-02-13 05:48:29 UTC
Thomas, I am going to work on this a bit.  Let me know if you have already done so.
Comment 6 Jerry DeLisle 2008-02-14 06:00:14 UTC
Created attachment 15147 [details]
Tentative patch

This patch fixes the test case when writing to an actual file, but not to stdio.  Stdout is not seekable so this won't work for that case.  We will have to do some more work on how we handle buffering of pre-connected units to do better than this, and I don't think its worth the effort.  (Tabbing in formats is a heck of a way to seek.  :)  Regression testing this now.
Comment 7 Jerry DeLisle 2008-02-14 06:07:09 UTC
Patch in comment #6 has a regression.
Comment 8 Jerry DeLisle 2008-02-15 04:18:16 UTC
Created attachment 15154 [details]
Revised patch

This patch regression tests OK.  Same issues with stdio.  Will commit for 4.4.
Comment 9 Jerry DeLisle 2008-02-21 02:27:59 UTC
Subject: Bug 34974

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

Comment 10 Jerry DeLisle 2008-02-21 02:34:11 UTC
Subject: Bug 34974

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

Comment 11 Jerry DeLisle 2008-02-21 02:44:39 UTC
Fixed on trunk, Committed as obvious.  Original test case now gives:

$ od -a test.dat 
0000000   a  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp
0000020  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp
*
3641060  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp  sp   b
3641100  nl


Comment 12 Jerry DeLisle 2008-05-06 04:01:08 UTC
Reverted patch which caused pr36131. Reopening this one.
Comment 13 Jerry DeLisle 2008-05-06 04:35:43 UTC
Janne, see discussion in comment #6
Comment 14 Jerry DeLisle 2008-05-07 02:29:39 UTC
Subject: Bug 34974

Author: jvdelisle
Date: Wed May  7 02:28:45 2008
New Revision: 135017

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

	PR libfortran/34974
	gfortran.dg/fmt_t_7.f: XFAIL this until we get issue resolved.

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

Comment 15 Janne Blomqvist 2008-05-15 18:33:04 UTC
Subject: Bug 34974

Author: jb
Date: Thu May 15 18:30:29 2008
New Revision: 135388

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135388
Log:
Remove XFAIL from gfortran.dg/fmt_t_7.f

2008-05-15  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/34974
	* gfortran.dg/fmt_t_7.f: Remove XFAIL, patch for PR 25561/Part 1 fixes
	this.

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

Comment 16 Janne Blomqvist 2008-05-15 18:35:37 UTC
Closing as fixed, see commit msg above.
Comment 17 Jerry DeLisle 2008-05-16 03:12:03 UTC
The test case needs { target fd_truncate }  I will fix it.