From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 46412 invoked by alias); 25 Apr 2018 00:15:44 -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 46311 invoked by uid 89); 25 Apr 2018 00:15:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=Steinmetz 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 ESMTP; Wed, 25 Apr 2018 00:15:35 +0000 Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id w3P0FXFH055746 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 24 Apr 2018 17:15:33 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id w3P0FXXW055745; Tue, 24 Apr 2018 17:15:33 -0700 (PDT) (envelope-from sgk) Date: Wed, 25 Apr 2018 07:38:00 -0000 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [Committed] PR fortran/85520 -- check for negative length Message-ID: <20180425001533.GA55709@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="k1lZvvs/B4yU6o8G" Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-SW-Source: 2018-04/txt/msg01115.txt.bz2 --k1lZvvs/B4yU6o8G Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 469 I've committed the attached patch after checking that it does not cause any regression and that it fixes the problem in the PR. The patch checks for a negative string length, and resets it to 0 if it is < 0. 2018-04-24 Steven G. Kargl PR fortran/85520 * decl.c (gfc_match_char_spec): Check for negative length and set to 0. 2018-04-24 Steven G. Kargl PR fortran/85520 * gfortran.dg/pr85520.f90: New test. -- Steve --k1lZvvs/B4yU6o8G Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="pr85520.diff" Content-length: 957 Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (revision 259619) +++ gcc/fortran/decl.c (working copy) @@ -3235,7 +3249,11 @@ done: e = gfc_copy_expr (len); gfc_reduce_init_expr (e); if (e->expr_type == EXPR_CONSTANT) - gfc_replace_expr (len, e); + { + gfc_replace_expr (len, e); + if (mpz_cmp_si (len->value.integer, 0) < 0) + mpz_set_ui (len->value.integer, 0); + } else gfc_free_expr (e); cl->length = len; Index: gcc/testsuite/gfortran.dg/pr85520.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr85520.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr85520.f90 (working copy) @@ -0,0 +1,7 @@ +! { dg-do run } +! PR fortran/85520 +! Original code from Gerhard Steinmetz +program p + character(-huge(1)) :: c = ' ' + if (len(c) /= 0) stop 1 +end --k1lZvvs/B4yU6o8G--