re PR fortran/48876 (ICE when initializing character variable with zero-length string)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 30 Jul 2011 18:17:55 +0000 (18:17 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 30 Jul 2011 18:17:55 +0000 (18:17 +0000)
2011-07-30  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/48876
* expr.c (gfc_simplify_expr):  If end of a string is less
than zero, set it to zero.

2011-07-30  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/48876
* gfortran.dg/string_5.f90:  New test.

From-SVN: r176961

gcc/fortran/ChangeLog
gcc/fortran/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/string_5.f90 [new file with mode: 0644]

index 89825e35cc480bc0adf7d5e24bb8086ac6df82e3..6be5141023b0c2e3d642c587ac67ea91f6b9a6f6 100644 (file)
@@ -1,3 +1,9 @@
+2011-07-30  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/48876
+       * expr.c (gfc_simplify_expr):  If end of a string is less
+       than zero, set it to zero.
+
 2011-07-28  Jakub Jelinek  <jakub@redhat.com>
 
        PR fortran/31067
index e5394b876df3d9f719e903e172d9bf069ab68eef..549feee61c7c63a7641cf5f30e1ad4f10a675b7d 100644 (file)
@@ -1839,6 +1839,9 @@ gfc_simplify_expr (gfc_expr *p, int type)
          if (p->ref && p->ref->u.ss.end)
            gfc_extract_int (p->ref->u.ss.end, &end);
 
+         if (end < 0)
+           end = 0;
+
          s = gfc_get_wide_string (end - start + 2);
          memcpy (s, p->value.character.string + start,
                  (end - start) * sizeof (gfc_char_t));
index 187a808fe514e588a2e70b2153fd72d3f7a44036..3a681d8d31552f4945ac01a8ed06f06e9e8107ad 100644 (file)
@@ -1,3 +1,8 @@
+2011-07-30  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/48876
+       * gfortran.dg/string_5.f90:  New test.
+
 2011-07-29  Jason Merrill  <jason@redhat.com>
 
        PR c++/49867
diff --git a/gcc/testsuite/gfortran.dg/string_5.f90 b/gcc/testsuite/gfortran.dg/string_5.f90
new file mode 100644 (file)
index 0000000..87ec709
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! PR fortran/48876 - this used to segfault.
+! Test case contributed by mhp77 (a) gmx.at.
+program test
+  character ::  string =  "string"( : -1 )
+end program test
+