This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, libgfortran] PR48960 OPEN statement modifies NEWUNIT variable on error
- From: Jerry DeLisle <jvdelisle at charter dot net>
- To: gfortran <fortran at gcc dot gnu dot org>
- Cc: gcc patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 25 Dec 2012 23:46:00 -0800
- Subject: [patch, libgfortran] PR48960 OPEN statement modifies NEWUNIT variable on error
The attached patch fixes this bug by not assigning the new unit value to the
user variable until after the OPEN is successful.
Regression tested on Linux X86-64.
OK for trunk with the test case from the PR?
Regards,
Jerry
2012-12-26 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libfortran/48960
* io/open.c (st_parameter_open): Assign newunit number to user
variable only if the the associated open statement is successful.
Index: open.c
===================================================================
--- open.c (revision 194678)
+++ open.c (working copy)
@@ -844,10 +844,7 @@ st_open (st_parameter_open *opp)
if ((opp->common.flags & IOPARM_LIBRETURN_MASK) == IOPARM_LIBRETURN_OK)
{
if ((opp->common.flags & IOPARM_OPEN_HAS_NEWUNIT))
- {
- *opp->newunit = get_unique_unit_number(opp);
- opp->common.unit = *opp->newunit;
- }
+ opp->common.unit = get_unique_unit_number(opp);
u = find_or_create_unit (opp->common.unit);
if (u->s == NULL)
@@ -859,6 +856,10 @@ st_open (st_parameter_open *opp)
else
already_open (opp, u, &flags);
}
-
+
+ if ((opp->common.flags & IOPARM_OPEN_HAS_NEWUNIT)
+ && (opp->common.flags & IOPARM_LIBRETURN_MASK) == IOPARM_LIBRETURN_OK)
+ *opp->newunit = opp->common.unit;
+
library_end ();
}