re PR fortran/47778 (reading two arrays of structures from namelist fails)
[gcc.git] / libgfortran / io / list_read.c
index 9d797cc270d260a3483c4a796ddc90a865c04b1d..ea232327f48b5f545b36c2fa84ad031a76331c0a 100644 (file)
@@ -2985,6 +2985,11 @@ namelist_read (st_parameter_dt *dtp)
 {
   int c;
   char nml_err_msg[200];
+
+  /* Initialize the error string buffer just in case we get an unexpected fail
+     somewhere and end up at nml_err_ret.  */
+  strcpy (nml_err_msg, "Internal namelist read error");
+
   /* Pointer to the previously read object, in case attempt is made to read
      new object name.  Should this fail, error message can give previous
      name.  */
@@ -3058,6 +3063,11 @@ find_nml_name:
            goto nml_err_ret;
          generate_error (&dtp->common, LIBERROR_READ_VALUE, nml_err_msg);
         }
+
+      /* Reset the previous namelist pointer if we know we are not going
+        to be doing multiple reads within a single namelist object.  */
+      if (prev_nl && prev_nl->var_rank == 0)
+       prev_nl = NULL;
     }
 
   free_saved (dtp);