summaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authorJerry DeLisle <jvdelisle@gcc.gnu.org>2019-01-14 00:22:00 +0000
committerJerry DeLisle <jvdelisle@gcc.gnu.org>2019-01-14 00:22:00 +0000
commit9c5f89006fa4b64c77997f660554a12315f4ac1d (patch)
treef238d50e7438578fcb6c31df6f1ab0ff3285495b /libgfortran
parentbff1a7315da774562db589a19a96ea522b47b900 (diff)
re PR libfortran/88776 (Namelist read from stdin: loss of data)
2019-01-13 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libfortran/88776 * io/open.c (newunit): Free format buffer if the unit specified is for stdin, stdout, or stderr. * gfortran.dg/namelist_96.f90: New test. From-SVN: r267910
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog6
-rw-r--r--libgfortran/io/open.c16
2 files changed, 18 insertions, 4 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index f63e3782734..274160d4b9e 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,9 @@
+2019-01-13 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
+ PR libfortran/88776
+ * io/open.c (newunit): Free format buffer if the unit specified is for
+ stdin, stdout, or stderr.
+
2019-01-12 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libfortran/88776
diff --git a/libgfortran/io/open.c b/libgfortran/io/open.c
index 97fb17c7424..b48afabf7a3 100644
--- a/libgfortran/io/open.c
+++ b/libgfortran/io/open.c
@@ -530,6 +530,14 @@ new_unit (st_parameter_open *opp, gfc_unit *u, unit_flags *flags)
if (u2 != NULL)
unlock_unit (u2);
+ /* If the unit specified is preconnected with a file specified to be open,
+ then clear the format buffer. */
+ if ((opp->common.unit == options.stdin_unit ||
+ opp->common.unit == options.stdout_unit ||
+ opp->common.unit == options.stderr_unit)
+ && (opp->common.flags & IOPARM_OPEN_HAS_FILE) != 0)
+ fbuf_destroy (u);
+
/* Open file. */
s = open_external (opp, flags);
@@ -705,12 +713,12 @@ already_open (st_parameter_open *opp, gfc_unit *u, unit_flags *flags)
if (u->filename && u->flags.status == STATUS_SCRATCH)
remove (u->filename);
#endif
- free (u->filename);
- u->filename = NULL;
-
+ free (u->filename);
+ u->filename = NULL;
+
u = new_unit (opp, u, flags);
if (u != NULL)
- unlock_unit (u);
+ unlock_unit (u);
return;
}