This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/29452] Keyword check for specifiers in WRITE, READ and OPEN/CLOSE



------- Comment #2 from tobias dot burnus at physik dot fu-berlin dot de  2006-10-17 15:31 -------
The library problems are due to an error in the string comparison; one only
compares the first (fortran string length) characters, but never checks whether
the strings are of identical length.

Patch:

Index: libgfortran/runtime/string.c
===================================================================
--- libgfortran/runtime/string.c        (revision 117796)
+++ libgfortran/runtime/string.c        (working copy)
@@ -44,6 +44,7 @@

   /* Strip trailing blanks from the Fortran string.  */
   len = fstrlen (s1, s1_len);
+  if(len != strlen(s2)) return 0; /* don't match */
   return strncasecmp (s1, s2, len) == 0;
 }


Similarly for WRITE(*,*,ADVANCE='YES/NO'):

Index: gcc/fortran/io.c
===================================================================
--- gcc/fortran/io.c    (revision 117796)
+++ gcc/fortran/io.c    (working copy)
@@ -2697,8 +2697,8 @@
       if (expr->expr_type == EXPR_CONSTANT && expr->ts.type == BT_CHARACTER)
        {
          const char * advance = expr->value.character.string;
-         not_no = strncasecmp (advance, "no", 2) != 0;
-         not_yes = strncasecmp (advance, "yes", 2) != 0;
+         not_no = strcasecmp (advance, "no") != 0;
+         not_yes = strcasecmp (advance, "yes") != 0;
        }
       else
        {

I will submit a patch in the next days.
(The other suggested checks for READ/WRITE are not yet needed as those options
are not supported, yet.
I don't know in how far strcasencmp problems occurre at other places as well.)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29452


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]