From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 37913 invoked by alias); 27 Mar 2015 22:47:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 37892 invoked by uid 89); 27 Mar 2015 22:47:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: troutmask.apl.washington.edu Received: from troutmask.apl.washington.edu (HELO troutmask.apl.washington.edu) (128.95.76.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 27 Mar 2015 22:47:46 +0000 Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.14.9/8.14.9) with ESMTP id t2RMliDP004503 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 27 Mar 2015 15:47:44 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.9/8.14.9/Submit) id t2RMlhsC004502; Fri, 27 Mar 2015 15:47:43 -0700 (PDT) (envelope-from sgk) Date: Fri, 27 Mar 2015 22:47:00 -0000 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] fortran/65429 -- don't dereference a null pointer Message-ID: <20150327224743.GA4459@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-03/txt/msg01467.txt.bz2 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 PR fortran/65429 * decl.c (add_init_expr_to_sym): Do not dereference a null pointer. 2015-03-27 Steven G. Kargl PR fortran/65429 * pr65429.f90: New test. -- Steve 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 +