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]

[PATCH] fortran/39893 -- fix segfault caused by invalid code


The attached patch has been regression tested on
i686-*-freebsd and x86_64-*-*freebsd.  There are
no regression.

The patch prevents a segmentation fault on invalid 
code.  The invalid code porduces an error, but gfortran
tries to continue and fails.

2009-04-26  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/39893
	* gfortran.dg/assumed_charlen_dummy.f90: New Test.


2009-04-26  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/39893
	fortran/data.c (gfc_assign_data_value): If the lvalue is an 
	assumed character length entity in a data statement, then 
	return FAILURE to prevent segmentation fault.

OK for trunk and 4.4?

-- 
Steve
Index: gcc/testsuite/gfortran.dg/assumed_charlen_dummy.f90
===================================================================
--- gcc/testsuite/gfortran.dg/assumed_charlen_dummy.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/assumed_charlen_dummy.f90	(revision 0)
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! Test the fix for PR fortran/39893.
+! Original testcase provided by Deji Akingunola.
+! Reduced testcase porivided by Dominique d'Humieres.
+!
+      SUBROUTINE XAUTOGET()
+      CHARACTER*(*) DICBA    ! { dg-error "Entity with assumed character" }
+      DATA DICBA /"CLIP" /
+      RETURN
+      END
Index: gcc/fortran/data.c
===================================================================
--- gcc/fortran/data.c	(revision 146793)
+++ gcc/fortran/data.c	(working copy)
@@ -416,7 +416,11 @@ gfc_assign_data_value (gfc_expr *lvalue,
     }
 
   if (ref || last_ts->type == BT_CHARACTER)
-    expr = create_character_intializer (init, last_ts, ref, rvalue);
+    {
+      if (lvalue->ts.cl->length == NULL && !(ref && ref->u.ss.length != NULL))
+	return FAILURE;
+      expr = create_character_intializer (init, last_ts, ref, rvalue);
+    }
   else
     {
       /* Overwriting an existing initializer is non-standard but usually only

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