re PR libfortran/17164 (index function not working properly)
authorBud Davis <bdavis9659@comcast.net>
Wed, 25 Aug 2004 00:14:07 +0000 (00:14 +0000)
committerBud Davis <bdavis@gcc.gnu.org>
Wed, 25 Aug 2004 00:14:07 +0000 (00:14 +0000)
2004-08-24  Bud Davis  <bdavis9659@comcast.net>

        PR fortran/17164
        * runtime/string_intrinsics.c (string_index):check for
        substring longer than string.
        * gfortran.dg/pr17164.f90: New test.

From-SVN: r86527

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr17164.f90 [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/intrinsics/string_intrinsics.c

index 23fff497d58d84e09077bae65855bab0b57b9fee..ba023348e2bfa86eb5e0be70b9623758ada8fab2 100644 (file)
@@ -1,3 +1,8 @@
+2004-08-24  Bud Davis  <bdavis9659@comcast.net>
+
+       PR fortran/17164
+       * gfortran.dg/pr17164.f90: New test.
+
 2004-08-24  Zdenek Dvorak  <rakdver@atrey.karlin.mff.cuni.cz>
 
        * 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 (file)
index 0000000..0cfd994
--- /dev/null
@@ -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
+
index 36b706960d7a5c19de2d037d9e6ee4b6f3325d53..1cb06dd46b980870a406e5c746452de7367d1752 100644 (file)
@@ -1,3 +1,9 @@
+2004-08-24  Bud Davis  <bdavis9659@comcast.net>
+
+       PR fortran/17164
+       * runtime/string_intrinsics.c (string_index):check for
+       substring longer than string.
+
 2004-08-24  David Edelsohn  <edelsohn@gnu.org>
 
        * Makefile.am (libgfortran_la_LDFLAGS): Add -lm.
index 2cd07a2b77b01794a17d6a624ea8f1ef9adc7f70..5d231268ab6d3962ce71dbe293b6ca38362fe09f 100644 (file)
@@ -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;