re PR libfortran/16080 (segmentation fault when reading empty string)
authorBud Davis <bdavis9659@comcast.net>
Sat, 19 Jun 2004 16:42:05 +0000 (16:42 +0000)
committerBud Davis <bdavis@gcc.gnu.org>
Sat, 19 Jun 2004 16:42:05 +0000 (16:42 +0000)
2004-06-19  Bud Davis  <bdavis9659@comcast.net>

      PR gfortran/16080
      * gfortran.fortran-torture/execute/read_null_string.f90: New file.
      * io/list_read.c(set_value): don't copy if the string is null.

From-SVN: r83388

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.fortran-torture/execute/read_null_string.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/io/list_read.c

index 92679a2092ed6f85269e9dd8d967840de4de9a8e..3061f0622480f242c26156b54f47117b83e6db45 100644 (file)
@@ -1,3 +1,8 @@
+2004-06-19  Bud Davis  <bdavis9659@comcast.net>
+        PR gfortran/16080
+       * gfortran.fortran-torture/execute/read_null_string.f90: New file.
+
 2004-06-19  Andrew Pinski  <pinskia@physics.uc.edu>
 
        * g++.dg/lookup/crash3.C: Use __SIZE_TYPE__
diff --git a/gcc/testsuite/gfortran.fortran-torture/execute/read_null_string.f90 b/gcc/testsuite/gfortran.fortran-torture/execute/read_null_string.f90
new file mode 100644 (file)
index 0000000..7cf9492
--- /dev/null
@@ -0,0 +1,15 @@
+! pr 16080, segfault on reading an empty string 
+      implicit none 
+      integer t 
+      character*20   temp_name 
+      character*2 quotes
+      open(unit=7,status='SCRATCH')
+      quotes = '""""'  ! "" in the file
+      write(7,*)1
+      write(7,'(A)')quotes
+      temp_name = 'hello'  ! make sure the read overwrites it
+      rewind(7)
+      read(7, *) t 
+      read(7, *) temp_name 
+      if (temp_name.ne.'') call abort
+      end
index f0e7d8d7483eaf0de8947295d3afdcb3ccc7490c..5d6a81654bc5020ea1fba049f580dbc69ea8ec67 100644 (file)
@@ -1,3 +1,8 @@
+2004-06-19  Bud Davis  <bdavis9659@comcast.net>
+
+       PR gfortran/16080
+       * io/list_read.c(set_value): don't copy if the string is null.
+
 2004-06-14  Bud Davis  <bdavis9659@comcast.net>
 
        PR gfortran/15292
index 2b62d31007ca2a3767181109a4a1a18036d81a67..aa22f8ad0ff8b46c2d833a8cb57b8fde2e0436ef 100644 (file)
@@ -1313,8 +1313,13 @@ set_value:
       break;
 
     case BT_CHARACTER:
-      m = (len < saved_used) ? len : saved_used;
-      memcpy (p, saved_string, m);
+      if (saved_string)
+       { 
+          m = (len < saved_used) ? len : saved_used;
+          memcpy (p, saved_string, m);
+       }
+      else    /* just delimeters encountered, nothing to copy but SPACE */
+        m = 0;
 
       if (m < len)
        memset (((char *) p) + m, ' ', len - m);