From patchwork Sat Jul 30 11:49:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 107501 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E0C07B6F69 for ; Sat, 30 Jul 2011 21:50:01 +1000 (EST) Received: (qmail 23653 invoked by alias); 30 Jul 2011 11:49:59 -0000 Received: (qmail 23640 invoked by uid 22791); 30 Jul 2011 11:49:59 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, TW_CP X-Spam-Check-By: sourceware.org Received: from cc-smtpout2.netcologne.de (HELO cc-smtpout2.netcologne.de) (89.1.8.212) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 30 Jul 2011 11:49:44 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id 87F3A11F1B; Sat, 30 Jul 2011 13:49:43 +0200 (CEST) Received: from [192.168.0.197] (xdsl-84-44-153-213.netcologne.de [84.44.153.213]) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA id 62EF811E85; Sat, 30 Jul 2011 13:49:42 +0200 (CEST) Message-ID: <4E33EFD6.3040209@netcologne.de> Date: Sat, 30 Jul 2011 13:49:42 +0200 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.17) Gecko/20110414 SUSE/3.1.10 Thunderbird/3.1.10 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran] Fix ice-on-valid PR 48876 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hello world, the attached, rather self-explanatory patch fixes PR 48876. OK for trunk? Thomas 2011-07-30 Thomas Koenig PR fortran/48876 * expr.c (gfc_simplify_expr): If end of a string is less than zero, set it to zero. 2011-07-30 Thomas Koenig PR fortran/48876 * gfortran.dg/string_5.f90: New test. ! { dg-do compile } ! PR fortran/48876 - this used to segfault. ! Test case contributed by mhp77 (a) gmx.at. program test character :: string = "string"( : -1 ) end program test Index: expr.c =================================================================== --- expr.c (Revision 176933) +++ expr.c (Arbeitskopie) @@ -1839,6 +1839,9 @@ gfc_simplify_expr (gfc_expr *p, int type) if (p->ref && p->ref->u.ss.end) gfc_extract_int (p->ref->u.ss.end, &end); + if (end < 0) + end = 0; + s = gfc_get_wide_string (end - start + 2); memcpy (s, p->value.character.string + start, (end - start) * sizeof (gfc_char_t));