diff mbox

fortran/65429 -- don't dereference a null pointer

Message ID 20150327224743.GA4459@troutmask.apl.washington.edu
State New
Headers show

Commit Message

Steve Kargl March 27, 2015, 10:47 p.m. UTC
The following patch avoids the dereferencing of
a null pointer, which led to an ICE.  The patch
here is a slight variation on the patch submitted
by drikosev at otenet dot gr.  The testcase is a
slight variation on the code submitted by FX.

Built and regression tested on x86_64-*-freebsd.

OK to commit?

2015-03-27  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/65429
	* decl.c (add_init_expr_to_sym): Do not dereference a null pointer.

2015-03-27  Steven G. Kargl  <kargl@gcc.gnu.org>

    PR fortran/65429
	* pr65429.f90: New test.

Comments

Tobias Burnus March 27, 2015, 11:50 p.m. UTC | #1
Steve Kargl wrote:
> The following patch avoids the dereferencing of
> a null pointer, which led to an ICE.  The patch
> here is a slight variation on the patch submitted
> by drikosev at otenet dot gr.  The testcase is a
> slight variation on the code submitted by FX.
>
> Built and regression tested on x86_64-*-freebsd.
> OK to commit?

OK. However, could you additionally add "if (len(s) /= 5) call abort" to 
the test, just to make sure. (It works, I tried it :-)

Thanks for the patch!

Tobias

> 2015-03-27  Steven G. Kargl  <kargl@gcc.gnu.org>
>
> 	PR fortran/65429
> 	* decl.c (add_init_expr_to_sym): Do not dereference a null pointer.
>
> 2015-03-27  Steven G. Kargl  <kargl@gcc.gnu.org>
>
>      PR fortran/65429
> 	* pr65429.f90: New test.
diff mbox

Patch

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 220943)
+++ gcc/fortran/decl.c	(working copy)
@@ -1406,7 +1406,7 @@  add_init_expr_to_sym (const char *name, 
 		    {
 		      gfc_constructor *c;
 		      c = gfc_constructor_first (init->value.constructor);
-		      clen = c->expr->value.character.length;
+		      clen = c ? c->expr->value.character.length : 0;
 		      sym->ts.u.cl->length
 				= gfc_get_int_expr (gfc_default_integer_kind,
 						    NULL, clen);
Index: gcc/testsuite/gfortran.dg/pr65429.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr65429.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/pr65429.f90	(working copy)
@@ -0,0 +1,8 @@ 
+! { dg-do run }
+! PR fortran/65429
+program foo
+character(*), parameter :: s(*)  = [ character(5) :: 'abcde', 'fghij' ]
+if (s(1) /= 'abcde') call abort
+if (s(2) /= 'fghij') call abort
+end program foo
+