public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, libgfortran] PR77707 formatted direct access: nextrec off by one
@ 2016-09-28  6:30 Jerry DeLisle
  2016-09-28 18:43 ` Steve Kargl
  0 siblings, 1 reply; 2+ messages in thread
From: Jerry DeLisle @ 2016-09-28  6:30 UTC (permalink / raw)
  To: fortran; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 285 bytes --]

I plan to commit the attached patch in the next few days. Fairly simple.

Regression tested on x86-64.

Regards,

Jerry

2016-09-27  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/77707
	io/transfer.c (next_record): Flush before calculating next_record.
	Correctly calculate.

[-- Attachment #2: pr77707.diff --]
[-- Type: text/x-patch, Size: 1079 bytes --]

diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index 6009c123..902c0201 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -3720,6 +3720,8 @@ next_record (st_parameter_dt *dtp, int done)
   else
     next_record_w (dtp, done);
 
+  fbuf_flush (dtp->u.p.current_unit, dtp->u.p.mode);
+
   if (!is_stream_io (dtp))
     {
       /* Since we have changed the position, set it to unspecified so
@@ -3733,8 +3735,8 @@ next_record (st_parameter_dt *dtp, int done)
 	  fp = stell (dtp->u.p.current_unit->s);
 	  /* Calculate next record, rounding up partial records.  */
 	  dtp->u.p.current_unit->last_record =
-	    (fp + dtp->u.p.current_unit->recl - 1) /
-	      dtp->u.p.current_unit->recl;
+	    (fp + dtp->u.p.current_unit->recl) /
+	      dtp->u.p.current_unit->recl - 1;
 	}
       else
 	dtp->u.p.current_unit->last_record++;
@@ -3743,7 +3745,6 @@ next_record (st_parameter_dt *dtp, int done)
   if (!done)
     pre_position (dtp);
 
-  fbuf_flush (dtp->u.p.current_unit, dtp->u.p.mode);
   smarkeor (dtp->u.p.current_unit->s);
 }
 

[-- Attachment #3: pr77707.f90 --]
[-- Type: text/x-fortran, Size: 325 bytes --]

! { dg-do run }
! PR77707 formatted direct access: nextrec off by one
program directaccess_formatted
  integer nextrec
  open(10, status='scratch', form='formatted', access='direct', recl=10*4)
  write(10,'(10i4)',rec=9) 1,2,3,4,5,6,7,8,9,10
  inquire(unit=10,nextrec=nextrec)
  if (nextrec.ne.10) call abort
  close(10)
end

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

* Re: [patch, libgfortran] PR77707 formatted direct access: nextrec off by one
  2016-09-28  6:30 [patch, libgfortran] PR77707 formatted direct access: nextrec off by one Jerry DeLisle
@ 2016-09-28 18:43 ` Steve Kargl
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Kargl @ 2016-09-28 18:43 UTC (permalink / raw)
  To: Jerry DeLisle; +Cc: fortran, GCC Patches

On Tue, Sep 27, 2016 at 10:15:40PM -0700, Jerry DeLisle wrote:
> I plan to commit the attached patch in the next few days. Fairly simple.
> 
> Regression tested on x86-64.
> 

Looks ok to me.

-- 
Steve

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

end of thread, other threads:[~2016-09-28 18:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-28  6:30 [patch, libgfortran] PR77707 formatted direct access: nextrec off by one Jerry DeLisle
2016-09-28 18:43 ` Steve Kargl

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).