diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 4ae0e5b350a..29294f7e740 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2011-11-08 Francois-Xavier Coudert + + PR fortran/50409 + * expr.c (gfc_simplify_expr): Substrings can't have negative + length. + 2011-11-08 Francois-Xavier Coudert PR fortran/50334 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 504c7cf7d6b..f2414559653 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -1853,8 +1853,8 @@ 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; + if (end < start) + end = start; s = gfc_get_wide_string (end - start + 2); memcpy (s, p->value.character.string + start, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b0cbbb6eb2e..de8cdc441a5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-11-08 Francois-Xavier Coudert + + PR fortran/50409 + * gcc/testsuite/gfortran.dg/string_5.f90: Improve testcase. + 2011-10-23 Jason Merrill PR c++/50835 diff --git a/gcc/testsuite/gfortran.dg/string_5.f90 b/gcc/testsuite/gfortran.dg/string_5.f90 index 87ec70942a5..ef291566b52 100644 --- a/gcc/testsuite/gfortran.dg/string_5.f90 +++ b/gcc/testsuite/gfortran.dg/string_5.f90 @@ -1,7 +1,14 @@ ! { dg-do compile } -! PR fortran/48876 - this used to segfault. -! Test case contributed by mhp77 (a) gmx.at. program test + + ! PR fortran/48876 - this used to segfault. + ! Test case contributed by mhp77 (a) gmx.at. character :: string = "string"( : -1 ) + + ! PR fortran/50409 + character v(3) + v = (/ ('123'(i:1), i = 3, 1, -1) /) + print *, v + end program test