summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>2005-03-31 15:30:06 +0000
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>2005-03-31 15:30:06 +0000
commit78e910ee71ff7a4087e965dce6fc840f56683d04 (patch)
treef9c088e9e155088b3460b11a74badd8a49363196
parentd6702b2603baffdc18fa4db8192d63d3d97fe471 (diff)
downloadppe42-gcc-78e910ee71ff7a4087e965dce6fc840f56683d04.tar.gz
ppe42-gcc-78e910ee71ff7a4087e965dce6fc840f56683d04.zip
PR libfortran/20660
* io/inquire.c (inquire_via_unit): Non-opened units should still be reported by an INQUIRE statement as existing. * io/transfer.c (data_transfer_init): Never accept negative units. PR libfortran/20660 * gfortran.dg/negative_unit.f: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@97326 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/negative_unit.f22
-rw-r--r--libgfortran/ChangeLog7
-rw-r--r--libgfortran/io/inquire.c7
-rw-r--r--libgfortran/io/transfer.c6
5 files changed, 46 insertions, 1 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4d30efb3dae..b6714aa40b2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2005-03-31 Francois-Xavier Coudert <coudert@clipper.ens.fr>
+
+ PR libfortran/20660
+ * gfortran.dg/negative_unit.f: New test.
+
2005-03-31 Mostafa Hagog <mustafa@il.ibm.com>
* gcc.dg/20050330-1.c: New test.
diff --git a/gcc/testsuite/gfortran.dg/negative_unit.f b/gcc/testsuite/gfortran.dg/negative_unit.f
new file mode 100644
index 00000000000..ba0d3cd1a4d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/negative_unit.f
@@ -0,0 +1,22 @@
+! {dg-do run}
+!
+! PR libfortran/20660 and other bugs (not filed in bugzilla) relating
+! to negative units
+!
+! Bugs submitted by Walt Brainerd
+ integer i
+ logical l
+
+ i = 0
+! gfortran created a 'fort.-1' file and wrote "Hello" in it
+ write (unit=-1, fmt=*, iostat=i) "Hello"
+ if (i <= 0) call abort
+
+ i = 0
+ open (unit=-11, file="xxx", iostat=i)
+ if (i <= 0) call abort
+
+ inquire (unit=-42, exist=l)
+ if (l) call abort
+
+ end
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index edc23af6ce9..027263899d0 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,10 @@
+2005-03-31 Francois-Xavier Coudert <coudert@clipper.ens.fr>
+
+ PR libfortran/20660
+ * io/inquire.c (inquire_via_unit): Non-opened units should still be
+ reported by an INQUIRE statement as existing.
+ * io/transfer.c (data_transfer_init): Never accept negative units.
+
2005-03-29 Dale Ranta <dir@lanl.gov>
Francois-Xavier Coudert <coudert@clipper.ens.fr>
diff --git a/libgfortran/io/inquire.c b/libgfortran/io/inquire.c
index 28c2f6afbc5..1f0fcac6530 100644
--- a/libgfortran/io/inquire.c
+++ b/libgfortran/io/inquire.c
@@ -46,7 +46,12 @@ inquire_via_unit (gfc_unit * u)
const char *p;
if (ioparm.exist != NULL)
- *ioparm.exist = (u != NULL);
+ {
+ if (ioparm.unit >= 0)
+ *ioparm.exist = 1;
+ else
+ *ioparm.exist = 0;
+ }
if (ioparm.opened != NULL)
*ioparm.opened = (u != NULL);
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index aed0aa90dbc..4d4832395d9 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -935,6 +935,12 @@ data_transfer_init (int read_flag)
current_unit = get_unit (read_flag);
if (current_unit == NULL)
{ /* Open the unit with some default flags. */
+ if (ioparm.unit < 0)
+ {
+ generate_error (ERROR_BAD_OPTION, "Bad unit number in OPEN statement");
+ library_end ();
+ return;
+ }
memset (&u_flags, '\0', sizeof (u_flags));
u_flags.access = ACCESS_SEQUENTIAL;
u_flags.action = ACTION_READWRITE;
OpenPOWER on IntegriCloud