From: Bud Davis Date: Wed, 25 Aug 2004 00:14:07 +0000 (+0000) Subject: re PR libfortran/17164 (index function not working properly) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=02d735f6bd9325efc25367cfd399557e19bb2532;p=gcc.git re PR libfortran/17164 (index function not working properly) 2004-08-24 Bud Davis PR fortran/17164 * runtime/string_intrinsics.c (string_index):check for substring longer than string. * gfortran.dg/pr17164.f90: New test. From-SVN: r86527 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 23fff497d58..ba023348e2b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-08-24 Bud Davis + + PR fortran/17164 + * gfortran.dg/pr17164.f90: New test. + 2004-08-24 Zdenek Dvorak * gcc.dg/tree-ssa/loop-1.c: New test. diff --git a/gcc/testsuite/gfortran.dg/pr17164.f90 b/gcc/testsuite/gfortran.dg/pr17164.f90 new file mode 100644 index 00000000000..0cfd9941774 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr17164.f90 @@ -0,0 +1,10 @@ +! pr17164 +! index aborts when substring is longer than string + implicit none + character*5 x + integer i + x='12345' + i=index(x,'blablabl') + if (i.ne.0) call abort + end + diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 36b706960d7..1cb06dd46b9 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2004-08-24 Bud Davis + + PR fortran/17164 + * runtime/string_intrinsics.c (string_index):check for + substring longer than string. + 2004-08-24 David Edelsohn * Makefile.am (libgfortran_la_LDFLAGS): Add -lm. diff --git a/libgfortran/intrinsics/string_intrinsics.c b/libgfortran/intrinsics/string_intrinsics.c index 2cd07a2b77b..5d231268ab6 100644 --- a/libgfortran/intrinsics/string_intrinsics.c +++ b/libgfortran/intrinsics/string_intrinsics.c @@ -221,6 +221,9 @@ string_index (GFC_INTEGER_4 slen, const char * str, GFC_INTEGER_4 sslen, if (sslen == 0) return 1; + if (sslen > slen) + return 0; + if (!back) { last = slen + 1 - sslen;