[Bug libfortran/95195] gfortran poorly handles a program error of writing a namelist to an unformatted file.
anlauf at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu May 21 19:32:59 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95195
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|fortran |libfortran
Priority|P3 |P4
--- Comment #2 from anlauf at gcc dot gnu.org ---
The following patch generates a runtime error for namelist read:
diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index 77d61421a0f..28744d21143 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -3549,6 +3549,14 @@ namelist_read (st_parameter_dt *dtp)
name. */
namelist_info *prev_nl = NULL;
+ if (dtp->u.p.current_unit->flags.form == FORM_UNFORMATTED)
+ {
+ generate_error (&dtp->common, LIBERROR_OPTION_CONFLICT,
+ "Namelist formatting not allowed for unit connected "
+ "with FORM='UNFORMATTED'");
+ return;
+ }
+
dtp->u.p.input_complete = 0;
dtp->u.p.expanded_read = 0;
This generates:
At line 10 of file pr95195.f90 (unit = 10, file = 'test.dat')
Fortran runtime error: Namelist formatting not allowed for unit connected with
FORM='UNFORMATTED'
Error termination. Backtrace:
#0 0x7f80d510f1a7 in finalize_transfer
at ../../../gcc-trunk/libgfortran/io/transfer.c:4128
#1 0x400b3b in test
at /home/anlauf/gcc-bugs/pr95195.f90:10
#2 0x400b9c in main
at /home/anlauf/gcc-bugs/pr95195.f90:12
Regtests cleanly for me.
Similar checks can be added for namelist write, list-directed formatting,
and non-advancing data transfers. (F2018: 12.3.3.3)
Does this look better?
More information about the Gcc-bugs
mailing list