[Committed] PR fortran/86110 -- Avoid NULL pointer dereference

Message ID 20180613194348.GA36553@troutmask.apl.washington.edu
State New
Headers show
Series
  • [Committed] PR fortran/86110 -- Avoid NULL pointer dereference
Related show

Commit Message

Steve Kargl June 13, 2018, 7:43 p.m.
Committed as obviously.

2018-06-13  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/86110
	* array.c (gfc_resolve_character_array_constructor): Avoid NULL 
	pointer dereference.

2018-06-13  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/86110
	* gfortran.dg/pr86110.f90: New test.

Comments

Paul Richard Thomas June 13, 2018, 10:25 p.m. | #1
Great! Thanks, Steve.

On 13 June 2018 at 20:43, Steve Kargl <sgk@troutmask.apl.washington.edu> wrote:
> Committed as obviously.
>
> 2018-06-13  Steven G. Kargl  <kargl@gcc.gnu.org>
>
>         PR fortran/86110
>         * array.c (gfc_resolve_character_array_constructor): Avoid NULL
>         pointer dereference.
>
> 2018-06-13  Steven G. Kargl  <kargl@gcc.gnu.org>
>
>         PR fortran/86110
>         * gfortran.dg/pr86110.f90: New test.
>
> --
> Steve

Patch

Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c	(revision 261521)
+++ gcc/fortran/array.c	(working copy)
@@ -2040,7 +2040,9 @@  got_charlen:
 	  gfc_ref *ref;
 	  for (ref = p->expr->ref; ref; ref = ref->next)
 	    if (ref->type == REF_SUBSTRING
+		&& ref->u.ss.start
 		&& ref->u.ss.start->expr_type == EXPR_CONSTANT
+		&& ref->u.ss.end
 		&& ref->u.ss.end->expr_type == EXPR_CONSTANT)
 	      break;
 
Index: gcc/testsuite/gfortran.dg/pr86110.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr86110.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr86110.f90	(working copy)
@@ -0,0 +1,7 @@ 
+! { dg-do compile }
+! PR fortran/86110
+program p
+   character(:), allocatable :: x, y
+   x = 'abc'
+   y = [x(:)]  ! { dg-error "Incompatible ranks 0 and 1" }
+end