[fortran] PR/83864 - ICE in gfc_apply_init, at fortran/expr.c:4271

Message ID 5A5FC8DF.4050803@gmx.de
State New
Headers show
Series
  • [fortran] PR/83864 - ICE in gfc_apply_init, at fortran/expr.c:4271
Related show

Commit Message

Harald Anlauf Jan. 17, 2018, 10:06 p.m.
The following obvious patch fixes a NULL pointer dereference:


Whoever wants to commit this to 8-trunk, please do so.

Thanks,
Harald

Comments

Steve Kargl Jan. 18, 2018, 7:54 a.m. | #1
On Wed, Jan 17, 2018 at 11:06:23PM +0100, Harald Anlauf wrote:
> 

> Changelog:

> 

> 2018-01-17  Harald Anlauf  <anlauf@gmx.de>

> 

> 	PR fortran/83864

> 	* expr.c (add_init_expr_to_sym): Do not dereference NULL pointer.

> 

> Testcase:

> 

> 2018-01-17  Harald Anlauf  <anlauf@gmx.de>

> 

> 	PR fortran/83864

> 	* gfortran.dg/pr83864.f90: New test.

> 


Committed revision 256837

-- 
Steve

Patch

Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 256671)
+++ gcc/fortran/expr.c	(working copy)
@@ -4267,7 +4269,7 @@ 
         gfc_set_constant_character_len (len, init, -1);
       else if (init
 	       && init->ts.type == BT_CHARACTER
-               && init->ts.u.cl
+               && init->ts.u.cl && init->ts.u.cl->length
                && mpz_cmp (ts->u.cl->length->value.integer,
                            init->ts.u.cl->length->value.integer))
         {

Regtests without new failures on i686-pc-linux-gnu.
Testcase derived from PR, see below.

Changelog:

2018-01-17  Harald Anlauf  <anlauf@gmx.de>

	PR fortran/83864
	* expr.c (add_init_expr_to_sym): Do not dereference NULL pointer.


Testcase:

2018-01-17  Harald Anlauf  <anlauf@gmx.de>

	PR fortran/83864
	* gfortran.dg/pr83864.f90: New test.


Index: gfortran.dg/pr83864.f90
===================================================================
--- gfortran.dg/pr83864.f90	(revision 0)
+++ gfortran.dg/pr83864.f90	(revision 0)
@@ -0,0 +1,13 @@ 
+! { dg-do run }
+! PR fortran/83864
+!
+! Derived from PR by Contributed by Gerhard Steinmetz <gscfq@t-online.de>
+!
+program p
+  implicit none
+  type t
+     character :: c(3) = transfer('abc','z',3)
+  end type t
+  type(t) :: x
+  if (any (x%c /= ["a", "b", "c"])) call abort ()
+end