diff mbox series

[Committed] PR fortran/85542 -- Avoid NULL dereference

Message ID 20180511190023.GA67700@troutmask.apl.washington.edu
State New
Headers show
Series [Committed] PR fortran/85542 -- Avoid NULL dereference | expand

Commit Message

Steve Kargl May 11, 2018, 7 p.m. UTC
I've committed the attached patch.  It checks for a valid
pointer before using it.

2018-05-11  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85542
	* expr.c (check_inquiry): Avoid NULL pointer dereference.
 
2018-05-11  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85542
	* gfortran.dg/pr85542.f90: New test.
diff mbox series

Patch

Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 259653)
+++ gcc/fortran/expr.c	(working copy)
@@ -2422,7 +2422,7 @@  check_inquiry (gfc_expr *e, int not_restricted)
 
 	/* Assumed character length will not reduce to a constant expression
 	   with LEN, as required by the standard.  */
-	if (i == 5 && not_restricted
+	if (i == 5 && not_restricted && ap->expr->symtree
 	    && ap->expr->symtree->n.sym->ts.type == BT_CHARACTER
 	    && (ap->expr->symtree->n.sym->ts.u.cl->length == NULL
 		|| ap->expr->symtree->n.sym->ts.deferred))
Index: gcc/testsuite/gfortran.dg/pr85542.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr85542.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr85542.f90	(working copy)
@@ -0,0 +1,7 @@ 
+! { dg-do compile }
+! PR fortran/85542
+function f(x)
+   character(*), intent(in) :: x
+   character((len((x)))) :: f
+   f = x
+end