Hi all,
To say the least, this is one of those disappointing bugs (sigh). I
scanned the change logs. This bug has been here since before the
merge to tree-ssa which is as far back on viewcvs I felt like going.
I have regression tested this patch on trunk and plan to commit to 4.3
and 4.1 shortly, under the simple, but obviously not obvious rule.
Mark, because this is such an insidious bug, I am requesting
permission to commit this to 4.2. I don't know the status of 4.2 at
the moment, but this patch should go in ASAP. (can it make release?)
Regression tested on x86-64-gnu-linux.
Regards,
Jerry
2007-05-09 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libfortran/31880
* io/unix.c (fd_alloc_r_at): Fix calculation of physical offset.
------------------------------------------------------------------------
Index: unix.c
===================================================================
*** unix.c (revision 124481)
--- unix.c (working copy)
*************** fd_alloc_r_at (unix_stream * s, int *len
*** 492,498 ****
if (n < 0)
return NULL;
! s->physical_offset = where + n;
s->active += n;
}
else
--- 492,498 ----
if (n < 0)
return NULL;
! s->physical_offset = m + n;
s->active += n;
}
else
*************** fd_alloc_r_at (unix_stream * s, int *len
*** 503,509 ****
if (do_read (s, s->buffer + s->active, &n) != 0)
return NULL;
! s->physical_offset = where + n;
s->active += n;
}
--- 503,509 ----
if (do_read (s, s->buffer + s->active, &n) != 0)
return NULL;
! s->physical_offset = m + n;
s->active += n;
}
------------------------------------------------------------------------
! { dg-do run }
! PR31880 silent data corruption in gfortran read statement
! Test from PR.
program r3
integer*4 a(1025),b(1025),c(1025),d(2048),e(1022)
a = 5
b = 6
c = 7
e = 8
do i=1,2048
d(i)=i
end do
open (3,file='a',form='unformatted')
write (3) a,b,c,d,e
rewind 3
d = 0
read (3) a,b,c,d
close (3)
if (d(1).ne.1) call abort
if (d(2048).ne.2048) call abort
end