From patchwork Sat Mar 24 12:46:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 890434 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-475412-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=netcologne.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="XKWL0ovh"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 407gCR4JS0z9s0R for ; Sat, 24 Mar 2018 23:46:57 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=r4N0bWTqQBaEmHKAV7NwOBpXja7SzVnS80GRI98eJ7wPYBrG4z 2omfQDolN1sQ2jyLOTxGwmZZjWGTFm2nQd4WP4uBIkyz0/YsN/A0QuIvtUx+099E qw1wWXJl8kX1IjMShHSB7qc+J9i6cIaKf7JNmtm+D0RCk2r8sHT28FMyQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=rXdsexN5bKBRrBGkMNWmUhrlQuM=; b=XKWL0ovhPSyZOEz0AV+4 CkTCaSLZHsWq5mW60jxlvF94fL9dZh+OxmkNfTAClEg3YSELZS+BSNQmFFhravJ8 JPI1yxNCwSxRvWABi58l+aAeVLlBctFBtuOMBEo9UYz8kqgQZlEhRVBrowV/QvoA Stx/J0Ze+gdoKHv6eMAAjxY= Received: (qmail 44687 invoked by alias); 24 Mar 2018 12:46:50 -0000 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 Received: (qmail 44626 invoked by uid 89); 24 Mar 2018 12:46:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=UD:length, H*Ad:U*tkoenig, UD:netcologne.de X-Spam-User: qpsmtpd, 2 recipients X-HELO: cc-smtpout1.netcologne.de Received: from cc-smtpout1.netcologne.de (HELO cc-smtpout1.netcologne.de) (89.1.8.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 24 Mar 2018 12:46:47 +0000 Received: from cc-smtpin1.netcologne.de (cc-smtpin1.netcologne.de [89.1.8.201]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id A633E134BC; Sat, 24 Mar 2018 13:46:44 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin1.netcologne.de (Postfix) with ESMTP id A2E8411DCF; Sat, 24 Mar 2018 13:46:44 +0100 (CET) Received: from [78.35.138.60] (helo=cc-smtpin1.netcologne.de) by localhost with ESMTP (eXpurgate 4.1.9) (envelope-from ) id 5ab648b4-029d-7f0000012729-7f000001afc6-1 for ; Sat, 24 Mar 2018 13:46:44 +0100 Received: from [192.168.178.68] (xdsl-78-35-138-60.netcologne.de [78.35.138.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin1.netcologne.de (Postfix) with ESMTPSA; Sat, 24 Mar 2018 13:46:43 +0100 (CET) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran] Fix empty substrings when simplifying Message-ID: Date: Sat, 24 Mar 2018 13:46:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Hell world, the attached patch is fairly self-explanatory, it fixes an out-of-memory condition. Regression-tested. OK for trunk? Regards Thomas 2018-03-24 Thomas Koenig PR fortran/70068 * expr.c (find_substring_ref): Change types of start, end and length variables to gfc_charlen_t. Set length to zero for empty substring. 2018-03-24 Thomas Koenig PR fortran/70068 * gfortran.dg/substr_7.f90: New test. Index: expr.c =================================================================== --- expr.c (revision 258501) +++ expr.c (working copy) @@ -1662,9 +1662,9 @@ cleanup: static bool find_substring_ref (gfc_expr *p, gfc_expr **newp) { - int end; - int start; - int length; + gfc_charlen_t end; + gfc_charlen_t start; + gfc_charlen_t length; gfc_char_t *chr; if (p->ref->u.ss.start->expr_type != EXPR_CONSTANT @@ -1674,9 +1674,12 @@ find_substring_ref (gfc_expr *p, gfc_expr **newp) *newp = gfc_copy_expr (p); free ((*newp)->value.character.string); - end = (int) mpz_get_ui (p->ref->u.ss.end->value.integer); - start = (int) mpz_get_ui (p->ref->u.ss.start->value.integer); - length = end - start + 1; + end = (gfc_charlen_t) mpz_get_ui (p->ref->u.ss.end->value.integer); + start = (gfc_charlen_t) mpz_get_ui (p->ref->u.ss.start->value.integer); + if (end >= start) + length = end - start + 1; + else + length = 0; chr = (*newp)->value.character.string = gfc_get_wide_string (length + 1); (*newp)->value.character.length = length;