[gfortran] patch to fix PR 16908, segfault on direct access I/O
Paul Brook
paul@codesourcery.com
Sat Aug 21 11:20:00 GMT 2004
On Saturday 21 August 2004 05:57, Bud Davis wrote:
> 2004-08-20 Bud Davis <bdavis9659@comcast.net>
>
> PR 16908
> * io/transfer.c (next_record_w): Do not blank pad.
> * io/transfer.c (next_record): Take into account partial records.
I tweaked the partial record rounding slightly, and applied as follows.
Paul
Index: transfer.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/libgfortran/io/transfer.c,v
retrieving revision 1.9
diff -u -p -r1.9 transfer.c
--- transfer.c 18 Aug 2004 01:20:06 -0000 1.9
+++ transfer.c 21 Aug 2004 11:04:45 -0000
@@ -1223,20 +1223,23 @@ next_record_w (int done)
switch (current_mode ())
{
case FORMATTED_DIRECT:
- case UNFORMATTED_DIRECT:
if (current_unit->bytes_left == 0)
break;
length = current_unit->bytes_left;
-
p = salloc_w (current_unit->s, &length);
+
if (p == NULL)
goto io_error;
memset (p, ' ', current_unit->bytes_left);
if (sfree (current_unit->s) == FAILURE)
goto io_error;
+ break;
+ case UNFORMATTED_DIRECT:
+ if (sfree (current_unit->s) == FAILURE)
+ goto io_error;
break;
case UNFORMATTED_SEQUENTIAL:
@@ -1304,6 +1307,7 @@ next_record_w (int done)
void
next_record (int done)
{
+ gfc_offset fp; /* file position */
current_unit->read_bad = 0;
@@ -1314,8 +1318,12 @@ next_record (int done)
current_unit->current_record = 0;
if (current_unit->flags.access == ACCESS_DIRECT)
- current_unit->last_record = file_position (current_unit->s)
- / current_unit->recl;
+ {
+ fp = file_position (current_unit->s);
+ /* Calculate next record, rounding up partial records. */
+ current_unit->last_record = (fp + curren_unit->recl - 1)
+ / current_unit->recl;
+ }
else
current_unit->last_record++;
More information about the Fortran
mailing list