Commit bd72d66c by Paul Brook Committed by Paul Brook

transfer.c (read_sf): Rename uinty to readlen.

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

From-SVN: r86831
parent c789f36b
2004-08-31 Paul Brook <paul@codesourcery.com> 2004-08-31 Paul Brook <paul@codesourcery.com>
* gfortran.dg/eof_1.f90: New test.
2004-08-31 Paul Brook <paul@codesourcery.com>
* gfortran.dg/list_read_1.f90: New file. * gfortran.dg/list_read_1.f90: New file.
2004-08-30 Mark Mitchell <mark@codesourcery.com> 2004-08-30 Mark Mitchell <mark@codesourcery.com>
......
! { dg-do run }
! Program to test for proper EOF errors when reading past the end of a file.
! We used to get this wrong when a formatted read followed a list formatted
! read.
program eof_1
character(len=5) :: s
open (unit=11, status="SCRATCH")
write (11, '(a)') "Hello"
rewind(11)
read(11, *) s
if (s .ne. "Hello") call abort
read(11, '(a5)', end=10) s
call abort
10 continue
close (11)
end
2004-08-31 Paul Brook <paul@codesourcery.com> 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. * list_read.c (eat_separator): Set at_eo when a '/' is seen.
2004-08-31 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de> 2004-08-31 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
......
...@@ -119,7 +119,7 @@ read_sf (int *length) ...@@ -119,7 +119,7 @@ read_sf (int *length)
{ {
static char data[SCRATCH_SIZE]; static char data[SCRATCH_SIZE];
char *base, *p, *q; char *base, *p, *q;
int n, unity; int n, readlen;
if (*length > SCRATCH_SIZE) if (*length > SCRATCH_SIZE)
p = base = line_buffer = get_mem (*length); p = base = line_buffer = get_mem (*length);
...@@ -129,24 +129,33 @@ read_sf (int *length) ...@@ -129,24 +129,33 @@ read_sf (int *length)
memset(base,'\0',*length); memset(base,'\0',*length);
current_unit->bytes_left = options.default_recl; current_unit->bytes_left = options.default_recl;
unity = 1; readlen = 1;
n = 0; n = 0;
do do
{ {
if (is_internal_unit()) 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. */ 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) if (q == NULL)
break; 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 (current_unit->unit_number == options.stdin_unit)
{ {
if (n <= 0) if (n <= 0)
...@@ -1345,12 +1354,6 @@ static void ...@@ -1345,12 +1354,6 @@ static void
finalize_transfer (void) finalize_transfer (void)
{ {
if (setjmp (g.eof_jump))
{
generate_error (ERROR_END, NULL);
return;
}
if ((ionml != NULL) && (ioparm.namelist_name != NULL)) if ((ionml != NULL) && (ioparm.namelist_name != NULL))
{ {
if (ioparm.namelist_read_mode) if (ioparm.namelist_read_mode)
...@@ -1363,6 +1366,12 @@ finalize_transfer (void) ...@@ -1363,6 +1366,12 @@ finalize_transfer (void)
if (current_unit == NULL) if (current_unit == NULL)
return; return;
if (setjmp (g.eof_jump))
{
generate_error (ERROR_END, NULL);
return;
}
if (ioparm.list_format && g.mode == READING) if (ioparm.list_format && g.mode == READING)
finish_list_read (); finish_list_read ();
else else
......
...@@ -751,7 +751,7 @@ mem_alloc_r_at (unix_stream * s, int *len, gfc_offset where) ...@@ -751,7 +751,7 @@ mem_alloc_r_at (unix_stream * s, int *len, gfc_offset where)
s->logical_offset = where + *len; s->logical_offset = where + *len;
n = (where - s->buffer_offset) - s->active; n = s->buffer_offset + s->active - where;
if (*len > n) if (*len > n)
*len = n; *len = n;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment