This is the mail archive of the gcc-patches@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]

[fortran] Fix a segfault in io.c:compare_to_allowed_values


Hi,

There are some tests in gfortran.dg starting to fail for x86
cross sh4 compiler with the segmentation fault.
These errors can't be reproduced with the bootstrapped native
i686-pc-linux-gnu compiler but can be seen if fortran/io.c was
recompiled with -g.  The fault occurs at

0x080721b6 in compare_to_allowed_values (specifier=0x85b8a08 "STATUS",
    allowed=0x8672810, allowed_f2003=0x0, allowed_gnu=0x0,
    value=0x95d9760 "foo", statement=0x85b9bac "CLOSE", warn=1 '\001')
    at ../../ORIG/trunk/gcc/fortran/io.c:1279

1278      for (i = 0; allowed[i]; i++)
1279        if (len == strlen(allowed[i])
1280            && strncasecmp (value, allowed[i], strlen(allowed[i])) == 0)
1281          return 1;

where i is 2 and this compare_to_allowed_values is called at

#1  0x08072f83 in gfc_match_close () at ../../ORIG/trunk/gcc/fortran/io.c:1750
1750          if (!compare_to_allowed_values ("STATUS", status, NULL, NULL,

and the 2nd argument 'status' is

1748          static const char * status[] = { "KEEP", "DELETE" };

which isn't terminated with a NULL pointer.  It looks all other
calls of compare_to_allowed_values use NULL terminated char *
arrays as its 2nd argument and the attached patch works for me.

Regards,
	kaz
--
	* io.c (gfc_match_close): Add NULL at the end of status.

--- ORIG/trunk/gcc/fortran/io.c	2006-10-15 12:14:10.000000000 +0900
+++ LOCAL/trunk/gcc/fortran/io.c	2006-10-15 18:16:39.000000000 +0900
@@ -1745,7 +1745,7 @@ gfc_match_close (void)
   /* Checks on the STATUS specifier.  */
   if (close->status && close->status->expr_type == EXPR_CONSTANT)
     {
-      static const char * status[] = { "KEEP", "DELETE" };
+      static const char * status[] = { "KEEP", "DELETE", NULL };
 
       if (!compare_to_allowed_values ("STATUS", status, NULL, NULL,
 				      close->status->value.character.string,


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