diff options
author | pbrook <pbrook@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-08-31 15:53:31 +0000 |
---|---|---|
committer | pbrook <pbrook@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-08-31 15:53:31 +0000 |
commit | 11de4bf919a5375316d3d5f0148205855f22a946 (patch) | |
tree | eeec759a476bd4d9d5f8e220e891469fe79a14bb /libgfortran | |
parent | 50a9015ddd0a2afc02a2cbf31b14d152547cf226 (diff) | |
download | gcc-11de4bf919a5375316d3d5f0148205855f22a946.tar.gz |
* io/transfer.c (read_sf): Rename uinty to readlen. Detect EOF.
(finalize_transfer): Move setjmp after namlist IO.
* io/unix.c (mem_alloc_r_at): Calculate remaining length correctly.
testsuite/
* gfortran.dg/eof_1.f90: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@86831 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/ChangeLog | 6 | ||||
-rw-r--r-- | libgfortran/io/transfer.c | 33 | ||||
-rw-r--r-- | libgfortran/io/unix.c | 2 |
3 files changed, 28 insertions, 13 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 28329d2608c..1c76245bb39 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,5 +1,11 @@ 2004-08-31 Paul Brook <paul@codesourcery.com> + * io/transfer.c (read_sf): Rename uinty to readlen. Detect EOF. + (finalize_transfer): Move setjmp after namlist IO. + * io/unix.c (mem_alloc_r_at): Calculate remaining length correctly. + +2004-08-31 Paul Brook <paul@codesourcery.com> + * list_read.c (eat_separator): Set at_eo when a '/' is seen. 2004-08-31 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de> diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 5d4dcd592a0..ca920724b0d 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -119,7 +119,7 @@ read_sf (int *length) { static char data[SCRATCH_SIZE]; char *base, *p, *q; - int n, unity; + int n, readlen; if (*length > SCRATCH_SIZE) p = base = line_buffer = get_mem (*length); @@ -129,24 +129,33 @@ read_sf (int *length) memset(base,'\0',*length); current_unit->bytes_left = options.default_recl; - unity = 1; + readlen = 1; n = 0; do { if (is_internal_unit()) { - /* unity may be modified inside salloc_r if + /* readlen may be modified inside salloc_r if is_internal_unit() is true. */ - unity = 1; + readlen = 1; } - q = salloc_r (current_unit->s, &unity); + q = salloc_r (current_unit->s, &readlen); if (q == NULL) break; - if (*q == '\n') + /* If we have a line without a terminating \n, drop through to + EOR below. */ + if (readlen < 1 & n == 0) { + generate_error (ERROR_END, NULL); + return NULL; + } + + if (readlen < 1 || *q == '\n') + { + /* ??? What is this for? */ if (current_unit->unit_number == options.stdin_unit) { if (n <= 0) @@ -1345,12 +1354,6 @@ static void finalize_transfer (void) { - if (setjmp (g.eof_jump)) - { - generate_error (ERROR_END, NULL); - return; - } - if ((ionml != NULL) && (ioparm.namelist_name != NULL)) { if (ioparm.namelist_read_mode) @@ -1363,6 +1366,12 @@ finalize_transfer (void) if (current_unit == NULL) return; + if (setjmp (g.eof_jump)) + { + generate_error (ERROR_END, NULL); + return; + } + if (ioparm.list_format && g.mode == READING) finish_list_read (); else diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index 0c652581c04..33d7fda4514 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -751,7 +751,7 @@ mem_alloc_r_at (unix_stream * s, int *len, gfc_offset where) s->logical_offset = where + *len; - n = (where - s->buffer_offset) - s->active; + n = s->buffer_offset + s->active - where; if (*len > n) *len = n; |