The following program segfaults when the input file has an empty string
specified.

        PROGRAM foo
        IMPLICIT NONE
        CHARACTER(len=10) var
        CHARACTER(len=10) sname
        NAMELIST /input/ var
        sname = 'howdy'
        WRITE(*,*) sname, "<<<"
        OPEN(unit=1,file="input.tmp",delim='apostrophe',status='unknown')
        READ(1,NML=input) var
        CLOSE(1)
        WRITE(*,*) var
        END PROGRAM foo

The input file is:

$ cat input.tmp
&INPUT
   var=''
/

The following patch fixes this problem:

Index: io/list_read.c
===================================================================
--- io/list_read.c      (revision 105987)
+++ io/list_read.c      (working copy)
@@ -799,8 +799,11 @@
              push_char (quote);
              break;
            }
-
          unget_char (c);
+
+         /* Must be an empty string. */
+
+         push_char('\0');
          goto done;

        CASE_SEPARATORS:


-- 
           Summary: Segfault when reading empty string in namelist file
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libfortran
        AssignedTo: jvdelisle at gcc dot gnu dot org
        ReportedBy: jvdelisle at gcc dot gnu dot org
  GCC host triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24584

Reply via email to