This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FORTRAN Patch for PR 1832 -list directed i/o overflow hangs,-fbounds-check doesn't detect.


PR 1832 -list directed i/o overflow hangs, -fbounds-check doesn't detect.

The problem is:
   character*120 file
   character*5 string
   file = "c:/dos/adir/bdir/cdir/text.doc"
   write( string, * ) "a ", file

gets stuck in an infinite loop when ran.


Some information:


The test case is not unique to character variables, it also hangs with integers and reals.

The submitter suggests that an error message should be produced when compiled with -fbounds-check.

The FORTRAN 77 standard prohibits list directed I/O to an internal file (see 12.2.5.2), which seems kind of harsh, as this could be handy:)

Provided below is a patch for consideration which solves this problem by writing only the data items that will fit into the internal file. It does not truncate when the internal file is full, it stops on the previous data item.

Since the code that triggers this problem is wrong (logic wise, you are trying to print more than will fit), I propose this as a vaild solution. No regressions caused on i686-pc-linux-gnu.


--bud davis




Index: gcc/libf2c/libI77/iio.c
===================================================================
RCS file: /cvs/gcc/gcc/libf2c/libI77/iio.c,v
retrieving revision 1.8
diff -c -3 -p -r1.8 iio.c
*** gcc/libf2c/libI77/iio.c     2 Jun 2002 14:34:31 -0000       1.8
--- gcc/libf2c/libI77/iio.c     28 Mar 2003 03:57:09 -0000
*************** z_getc (void)
*** 21,27 ****
void
z_putc (int c)
{
!   if (f__icptr < f__icend && f__recpos++ < f__svic->icirlen)
   *f__icptr++ = c;
}
int
--- 21,27 ----
void
z_putc (int c)
{
!   if (f__recpos++ < f__svic->icirlen && f__icptr < f__icend)
   *f__icptr++ = c;
}
int



Here is a testcase that calls abort if it is wrong.

   implicit none
   character*120 file
   character*5 string
   file = "c:/dos/adir/bdir/cdir/text.doc"
   write( string, * ) "a ", file
   if (string.ne.' a') call abort
C-- the leading space is normal for unformatted output
C-- "file" is not printed because it would overflow "string"
   stop
   end








Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]