aboutsummaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog8
-rw-r--r--libgfortran/io/close.c13
-rw-r--r--libgfortran/io/open.c10
3 files changed, 29 insertions, 2 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 3eaf75d..956b43d 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,11 @@
+2025-04-13 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
+ PR libfortran/119502
+ * io/close.c (st_close): Issue an error and avoid
+ calling close_share when there is no stream assigned.
+ * io/open.c (st_open): If there is no stream assigned
+ to the unit, unlock the unit and issue an error.
+
2025-04-09 Paul Thomas <pault@gcc.gnu.org>
and Harald Anlauf <anlauf@gcc.gnu.org>
diff --git a/libgfortran/io/close.c b/libgfortran/io/close.c
index 8122311..41d278c 100644
--- a/libgfortran/io/close.c
+++ b/libgfortran/io/close.c
@@ -84,8 +84,17 @@ st_close (st_parameter_close *clp)
if (u != NULL)
{
- if (close_share (u) < 0)
- generate_error (&clp->common, LIBERROR_OS, "Problem in CLOSE");
+ if (u->s == NULL)
+ {
+ if (u->unit_number < 0)
+ generate_error (&clp->common, LIBERROR_BAD_UNIT,
+ "Unit number is negative with no associated file");
+ library_end ();
+ return;
+ }
+ else
+ if (close_share (u) < 0)
+ generate_error (&clp->common, LIBERROR_OS, "Problem in CLOSE");
if (u->flags.status == STATUS_SCRATCH)
{
if (status == CLOSE_KEEP)
diff --git a/libgfortran/io/open.c b/libgfortran/io/open.c
index 06ddf7f..e9fb0a7 100644
--- a/libgfortran/io/open.c
+++ b/libgfortran/io/open.c
@@ -912,6 +912,16 @@ st_open (st_parameter_open *opp)
library_end ();
return;
}
+
+ if (u->s == NULL)
+ {
+ unlock_unit (u);
+ generate_error (&opp->common, LIBERROR_BAD_OPTION,
+ "Unit number is negative and unit was not already "
+ "opened with OPEN(NEWUNIT=...)");
+ library_end ();
+ return;
+ }
}
if (u == NULL)