Bug 24489 - read_block wrong execution order
Summary: read_block wrong execution order
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Jerry DeLisle
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-22 22:54 UTC by Jerry DeLisle
Modified: 2005-10-25 15:00 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Fix for this PR (588 bytes, patch)
2005-10-22 22:58 UTC, Jerry DeLisle
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jerry DeLisle 2005-10-22 22:54:30 UTC
The following test case reads past the end of record because sf_read is being executed before the check for length is performed.  Discovered during testing of arrayio.  See message: http://gcc.gnu.org/ml/fortran/2005-10/msg00382.html

The following simplified test case shows the problem without using my arrayio patches not yet committed.

program read_block
  character*4, dimension(8) :: abuf = (/"0123","4567","89AB","CDEF", &
                                        "0123","4567","89AB","CDEF"/)
  character*4, dimension(2,4) :: buf
  character*8 :: a
  equivalence (buf,abuf)
  read(buf, '(a8)') a
  print *, a
end program read_block

gfortran gives:

$ ./a.out
 01234567

ifort gives:

$ ./a.out
 0123
Comment 1 Jerry DeLisle 2005-10-22 22:58:53 UTC
Created attachment 10045 [details]
Fix for this PR

The attached patch fixes this PR.  I will commit to mainline as obvious.
Comment 2 GCC Commits 2005-10-24 03:50:18 UTC
Subject: Bug 24489

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jvdelisle@gcc.gnu.org	2005-10-24 03:50:15

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: pr24489.f90 

Log message:
	2005-10-23  Jerry DeLisle  <jvdelisle@verizon.net>
	
	PR libgfortran/24489
	* gfortran.dg/pr24489.f90: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6239&r2=1.6240
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/pr24489.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 3 GCC Commits 2005-10-24 03:51:26 UTC
Subject: Bug 24489

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jvdelisle@gcc.gnu.org	2005-10-24 03:51:24

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

Log message:
	2005-10-23  Jerry DeLisle  <jvdelisle@verizon.net>
	
	PR libgfortran/24489
	* io/transfer.c (read_block): Change the order of execution to not read
	past end-of-record.
	(read_block_direct): Same change.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.332&r2=1.333
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/io/transfer.c.diff?cvsroot=gcc&r1=1.63&r2=1.64

Comment 4 Jerry DeLisle 2005-10-24 05:07:19 UTC
Fixed in 4.1, bug does not occur in 4.0 because arrayio has not been committed there.
Comment 5 Jerry DeLisle 2005-11-11 20:31:12 UTC
Subject: Bug 24489

Author: jvdelisle
Date: Fri Nov 11 20:31:06 2005
New Revision: 106798

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106798
Log:
2005-11-11  Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR libgfortran/24719
	gfortran.dg/read_noadvance.f90: New test.
	
	PR libgfortran/24699
	gfortran.dg/fmt_t_2.f90: New test.
	
	PR libgfortran/24785
	gfortran.dg/read_x_eor.f90: New test.
	
	PR libgfortran/24584
	gfortran.dg/namelist_empty.f90: Rename test.

	PR libgfortran/24489
	gfortran/read_eor.f90: Rename test.

Added:
    trunk/gcc/testsuite/gfortran.dg/fmt_t_2.f90
    trunk/gcc/testsuite/gfortran.dg/namelist_empty.f90
    trunk/gcc/testsuite/gfortran.dg/read_eor.f90
    trunk/gcc/testsuite/gfortran.dg/read_noadvance.f90
    trunk/gcc/testsuite/gfortran.dg/read_x_eor.f90