diff options
author | Steven G. Kargl <kargls@comcast.net> | 2005-11-12 19:16:40 +0000 |
---|---|---|
committer | Steven G. Kargl <kargl@gcc.gnu.org> | 2005-11-12 19:16:40 +0000 |
commit | 02c92593ed3d6da29ba15a4f9945b7c3885e2700 (patch) | |
tree | 8239450c8992785e8453dad9df487fe0211c246b /libgfortran | |
parent | 230dedb3272fa440ac35dcfb607c56221b1f18fa (diff) | |
download | gcc-02c92593ed3d6da29ba15a4f9945b7c3885e2700.zip gcc-02c92593ed3d6da29ba15a4f9945b7c3885e2700.tar.gz gcc-02c92593ed3d6da29ba15a4f9945b7c3885e2700.tar.bz2 |
re PR libfortran/24787 ([libfortran] SCAN is broken)
PR libfortran/24787
* intrinsics/string_intrinsics.c (string_scan): Off by one; Fix
typos in nearby comment.
* gfortran.dg/scan_1.f90: New test.
From-SVN: r106828
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/ChangeLog | 6 | ||||
-rw-r--r-- | libgfortran/intrinsics/string_intrinsics.c | 45 |
2 files changed, 26 insertions, 25 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 6ee5271..793d440 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2005-11-12 Steven G. Kargl <kargls@comcast.net> + + PR libgfortran/24787 + * intrinsics/string_intrinsics.c (string_scan): Off by one; Fix typos + in nearby comment. + 2005-11-10 Andreas Jaeger <aj@suse.de> * libgfortran.h: Add proper defines where needed. diff --git a/libgfortran/intrinsics/string_intrinsics.c b/libgfortran/intrinsics/string_intrinsics.c index f13d117..eed41d7 100644 --- a/libgfortran/intrinsics/string_intrinsics.c +++ b/libgfortran/intrinsics/string_intrinsics.c @@ -1,5 +1,5 @@ /* String intrinsics helper functions. - Copyright 2002 Free Software Foundation, Inc. + Copyright 2002, 2005 Free Software Foundation, Inc. Contributed by Paul Brook <paul@nowt.org> This file is part of the GNU Fortran 95 runtime library (libgfortran). @@ -89,12 +89,10 @@ copy_string (GFC_INTEGER_4 destlen, char * dest, { /* This will truncate if too long. */ memmove (dest, src, destlen); - /*memcpy (dest, src, destlen);*/ } else { memmove (dest, src, srclen); - /*memcpy (dest, src, srclen);*/ /* Pad with spaces. */ memset (&dest[srclen], ' ', destlen - srclen); } @@ -304,35 +302,32 @@ GFC_INTEGER_4 string_scan (GFC_INTEGER_4 slen, const char * str, GFC_INTEGER_4 setlen, const char * set, GFC_LOGICAL_4 back) { - int start; - int last; - int i; - int delta; + int i, j; if (slen == 0 || setlen == 0) return 0; if (back) { - last = 0; - start = slen - 1; - delta = -1; + for (i = slen - 1; i >= 0; i--) + { + for (j = 0; j < setlen; j++) + { + if (str[i] == set[j]) + return (i + 1); + } + } } else { - last = slen - 1; - start = 0; - delta = 1; - } - - i = 0; - for (; start != last; start += delta) - { - for (i = 0; i < setlen; i++) - { - if (str[start] == set[i]) - return (start + 1); - } + for (i = 0; i < slen; i++) + { + for (j = 0; j < setlen; j++) + { + if (str[i] == set[j]) + return (i + 1); + } + } } return 0; @@ -340,8 +335,8 @@ string_scan (GFC_INTEGER_4 slen, const char * str, GFC_INTEGER_4 setlen, /* Verify that a set of characters contains all the characters in a - string by indentifying the position of the first character in a - characters that dose not appear in a given set of characters. */ + string by identifying the position of the first character in a + characters that does not appear in a given set of characters. */ GFC_INTEGER_4 string_verify (GFC_INTEGER_4 slen, const char * str, GFC_INTEGER_4 setlen, |