This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, libgfortran] PR47778 reading two arrays of structures from namelist fails


On 02/27/2011 07:34 AM, Jerry DeLisle wrote:
Hi all,

The attached patch fixes this bug by resetting the pprev_nl pointer to NULL when
the rank of the previous object read was zero. pprev_nl is used to track
multiple reads from the same namelist variable.

Regression tested on x86-64.

OK for trunk? I suggest we should back port to 4.5 and possibly earlier.

Regards,

Jerry

2011-02-27 Jerry DeLisle <jvdelisle@gcc.gnu.org>

PR libgfortran/47778
* io/list_read.c (namelist_read): If pprev_nl was used during the
previous namelist read and the rank was zero, reset the pointer to NULL
for the next namelist read.


Index: io/list_read.c =================================================================== --- io/list_read.c (revision 170543) +++ io/list_read.c (working copy) @@ -3058,6 +3058,8 @@ goto nml_err_ret; generate_error (&dtp->common, LIBERROR_READ_VALUE, nml_err_msg); } + if (prev_nl && prev_nl->var_rank == 0) + prev_nl = NULL; }

free_saved (dtp);

I am going to add this snippet as obvious. There are code paths that can lead to unexpected calling of the error message without it being initialized as was the case with this PR before the fix. This will prevent accessing uninitialized memory. ChangeLog will be adjusted.


Index: io/list_read.c
===================================================================
--- io/list_read.c	(revision 170543)
+++ io/list_read.c	(working copy)
@@ -2985,6 +2985,9 @@
 {
   int c;
   char nml_err_msg[200];
+
+  snprintf (nml_err_msg, sizeof 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.  */


Jerry



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]