From: Bud Davis Date: Sat, 19 Jun 2004 16:42:05 +0000 (+0000) Subject: re PR libfortran/16080 (segmentation fault when reading empty string) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=04b0faec0878e8b47e732369bad771e8297a6baa;p=gcc.git re PR libfortran/16080 (segmentation fault when reading empty string) 2004-06-19 Bud Davis 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 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 92679a2092e..3061f062248 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-06-19 Bud Davis + + PR gfortran/16080 + * gfortran.fortran-torture/execute/read_null_string.f90: New file. + 2004-06-19 Andrew Pinski * 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 index 00000000000..7cf949204dc --- /dev/null +++ b/gcc/testsuite/gfortran.fortran-torture/execute/read_null_string.f90 @@ -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 diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index f0e7d8d7483..5d6a81654bc 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,8 @@ +2004-06-19 Bud Davis + + PR gfortran/16080 + * io/list_read.c(set_value): don't copy if the string is null. + 2004-06-14 Bud Davis PR gfortran/15292 diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c index 2b62d31007c..aa22f8ad0ff 100644 --- a/libgfortran/io/list_read.c +++ b/libgfortran/io/list_read.c @@ -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);