From 83437e6709a57a4a8552e4a6a4b5b94b1ff34d82 Mon Sep 17 00:00:00 2001 From: Jerry DeLisle Date: Sun, 31 Mar 2013 20:32:33 +0000 Subject: re PR libfortran/56786 (Namelist read fails with designators containing embedded spaces) 2013-03-31 Jerry DeLisle 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 false 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. From-SVN: r197290 --- libgfortran/io/list_read.c | 51 +++++++++++++++++++++++++++++++--------------- libgfortran/io/transfer.c | 2 +- 2 files changed, 36 insertions(+), 17 deletions(-) (limited to 'libgfortran/io') diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c index 7ce727d..be961f1 100644 --- a/libgfortran/io/list_read.c +++ b/libgfortran/io/list_read.c @@ -2078,7 +2078,7 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, /* The next character in the stream should be the '('. */ if ((c = next_char (dtp)) == EOF) - return false; + goto err_ret; /* Process the qualifier, by dimension and triplet. */ @@ -2092,7 +2092,7 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, /* Process a potential sign. */ if ((c = next_char (dtp)) == EOF) - return false; + goto err_ret; switch (c) { case '-': @@ -2110,11 +2110,12 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, /* Process characters up to the next ':' , ',' or ')'. */ for (;;) { - if ((c = next_char (dtp)) == EOF) - return false; - + c = next_char (dtp); switch (c) { + case EOF: + goto err_ret; + case ':': is_array_section = 1; break; @@ -2137,10 +2138,8 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, 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 false; break; default: @@ -2282,6 +2281,15 @@ nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad, 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 true; + } return false; } @@ -2751,12 +2759,12 @@ nml_get_obj_data (st_parameter_dt *dtp, namelist_info **pprev_nl, return true; if ((c = next_char (dtp)) == EOF) - return false; + goto nml_err_ret; switch (c) { case '=': if ((c = next_char (dtp)) == EOF) - return false; + goto nml_err_ret; if (c != '?') { snprintf (nml_err_msg, nml_err_msg_size, @@ -2806,8 +2814,9 @@ get_name: if (!is_separator (c)) push_char (dtp, tolower(c)); if ((c = next_char (dtp)) == EOF) - return false; - } while (!( c=='=' || c==' ' || c=='\t' || c =='(' || c =='%' )); + goto nml_err_ret; + } + while (!( c=='=' || c==' ' || c=='\t' || c =='(' || c =='%' )); unget_char (dtp, c); @@ -2882,7 +2891,7 @@ get_name: qualifier_flag = 1; if ((c = next_char (dtp)) == EOF) - return false; + goto nml_err_ret; unget_char (dtp, c); } else if (nl->var_rank > 0) @@ -2909,7 +2918,7 @@ get_name: component_flag = 1; if ((c = next_char (dtp)) == EOF) - return false; + goto nml_err_ret; goto get_name; } @@ -2946,7 +2955,7 @@ get_name: } if ((c = next_char (dtp)) == EOF) - return false; + goto nml_err_ret; unget_char (dtp, c); } @@ -2986,7 +2995,7 @@ get_name: return true; if ((c = next_char (dtp)) == EOF) - return false; + goto nml_err_ret; if (c != '=') { @@ -3021,6 +3030,16 @@ get_name: 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 true; + } return false; } diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 6fa954c..bb93009 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -3840,7 +3840,7 @@ hit_eof (st_parameter_dt * dtp) 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; -- cgit v1.1