diff options
Diffstat (limited to 'libgfortran/io')
-rw-r--r-- | libgfortran/io/transfer.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 7449f02d3dd..59eb22d3dec 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -1160,10 +1160,23 @@ data_transfer_init (int read_flag) if (g.mode == READING && current_unit->mode == WRITING) flush(current_unit->s); + /* Check whether the record exists to be read. Only + a partial record needs to exist. */ + + if (g.mode == READING && (ioparm.rec -1) + * current_unit->recl >= file_length (current_unit->s)) + { + generate_error (ERROR_BAD_OPTION, "Non-existing record number"); + return; + } + /* Position the file. */ if (sseek (current_unit->s, (ioparm.rec - 1) * current_unit->recl) == FAILURE) - generate_error (ERROR_OS, NULL); + { + generate_error (ERROR_OS, NULL); + return; + } } /* Overwriting an existing sequential file ? |