+2013-04-28 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
+ Backport from trunk:
+
+ PR fortran/56786
+ * gfortran.dg/namelist_81.f90: New test.
+
2013-04-28 Jerry DeLisle <jvdelisle@gcc.gnu.org>
Backport from trunk:
--- /dev/null
+! { dg-do run }
+! PR56786 Error on embedded spaces
+integer :: i(3)
+namelist /nml/ i
+
+i = -42
+open(99,status='scratch')
+write(99,'(a)') '&nml i(3 ) = 5 /'
+rewind(99)
+read(99,nml=nml)
+close(99)
+if (i(1)/=-42 .or. i(2)/=-42 .or. i(3)/=5) call abort()
+
+! Shorten the file so the read hits EOF
+
+open(99,status='scratch')
+write(99,'(a)') '&nml i(3 ) = 5 '
+rewind(99)
+read(99,nml=nml, end=30)
+call abort()
+! Shorten some more
+ 30 close(99)
+open(99,status='scratch')
+write(99,'(a)') '&nml i(3 ) ='
+rewind(99)
+read(99,nml=nml, end=40)
+call abort()
+! Shorten some more
+ 40 close(99)
+open(99,status='scratch')
+write(99,'(a)') '&nml i(3 )'
+rewind(99)
+read(99,nml=nml, end=50)
+call abort()
+! Shorten some more
+ 50 close(99)
+open(99,status='scratch')
+write(99,'(a)') '&nml i(3 '
+rewind(99)
+read(99,nml=nml, end=60)
+call abort()
+ 60 close(99)
+end
+2013-04-28 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
+ Backport from mainline:
+
+ PR libfortran/56786
+ * io/list_read.c (nml_parse_qualifier): Remove spurious next_char call
+ when checking for EOF. Use error return mechanism when EOF detected.
+ Do not return FAILURE unless parse_err_msg and parse_err_msg_size have
+ been set. Use hit_eof.
+ (nml_get_obj_data): Likewise use the correct error mechanism.
+ * io/transfer.c (hit_eof): Do not set AFTER_ENDFILE if in namelist
+ mode.
+
2013-04-28 Jerry DeLisle <jvdelisle@gcc.gnu.org>
Backport from mainline:
/* The next character in the stream should be the '('. */
if ((c = next_char (dtp)) == EOF)
- return FAILURE;
+ goto err_ret;
/* Process the qualifier, by dimension and triplet. */
/* Process a potential sign. */
if ((c = next_char (dtp)) == EOF)
- return FAILURE;
+ goto err_ret;
switch (c)
{
case '-':
/* Process characters up to the next ':' , ',' or ')'. */
for (;;)
{
- if ((c = next_char (dtp)) == EOF)
- return FAILURE;
-
+ c = next_char (dtp);
switch (c)
{
+ case EOF:
+ goto err_ret;
+
case ':':
is_array_section = 1;
break;
push_char (dtp, c);
continue;
- case ' ': case '\t':
+ case ' ': case '\t': case '\r': case '\n':
eat_spaces (dtp);
- if ((c = next_char (dtp) == EOF))
- return FAILURE;
break;
default:
err_ret:
+ /* The EOF error message is issued by hit_eof. Return true so that the
+ caller does not use parse_err_msg and parse_err_msg_size to generate
+ an unrelated error message. */
+ if (c == EOF)
+ {
+ hit_eof (dtp);
+ dtp->u.p.input_complete = 1;
+ return SUCCESS;
+ }
return FAILURE;
}
return SUCCESS;
if ((c = next_char (dtp)) == EOF)
- return FAILURE;
+ goto nml_err_ret;
switch (c)
{
case '=':
if ((c = next_char (dtp)) == EOF)
- return FAILURE;
+ goto nml_err_ret;
if (c != '?')
{
snprintf (nml_err_msg, nml_err_msg_size,
if (!is_separator (c))
push_char (dtp, tolower(c));
if ((c = next_char (dtp)) == EOF)
- return FAILURE;
- } while (!( c=='=' || c==' ' || c=='\t' || c =='(' || c =='%' ));
+ goto nml_err_ret;
+ }
+ while (!( c=='=' || c==' ' || c=='\t' || c =='(' || c =='%' ));
unget_char (dtp, c);
qualifier_flag = 1;
if ((c = next_char (dtp)) == EOF)
- return FAILURE;
+ goto nml_err_ret;
unget_char (dtp, c);
}
else if (nl->var_rank > 0)
component_flag = 1;
if ((c = next_char (dtp)) == EOF)
- return FAILURE;
+ goto nml_err_ret;
goto get_name;
}
}
if ((c = next_char (dtp)) == EOF)
- return FAILURE;
+ goto nml_err_ret;
unget_char (dtp, c);
}
return SUCCESS;
if ((c = next_char (dtp)) == EOF)
- return FAILURE;
+ goto nml_err_ret;
if (c != '=')
{
nml_err_ret:
+ /* The EOF error message is issued by hit_eof. Return true so that the
+ caller does not use nml_err_msg and nml_err_msg_size to generate
+ an unrelated error message. */
+ if (c == EOF)
+ {
+ dtp->u.p.input_complete = 1;
+ unget_char (dtp, c);
+ hit_eof (dtp);
+ return SUCCESS;
+ }
+
return FAILURE;
}
case NO_ENDFILE:
case AT_ENDFILE:
generate_error (&dtp->common, LIBERROR_END, NULL);
- if (!is_internal_unit (dtp))
+ if (!is_internal_unit (dtp) && !dtp->u.p.namelist_mode)
{
dtp->u.p.current_unit->endfile = AFTER_ENDFILE;
dtp->u.p.current_unit->current_record = 0;