From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 1F38C3814FC1 for ; Mon, 30 May 2022 08:33:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1F38C3814FC1 Received: by mail-wr1-x42b.google.com with SMTP id d26so8000387wrb.13 for ; Mon, 30 May 2022 01:33:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=L2etSIrXGizRoy0QBnuPFbMh4DEJ5Js+7vy3yKq3soc=; b=ZoFKamK9/JghKpWlASI+YBFutPNRGPUr+dlhKI/XE4hnvuXAmxzCfMsXbZaU1uUdbb 3mumxazWUJc8ZoMVfKMS4NIxxWt0TZaSt5qo+aaDRf1BoFzOVr8sblCToSMhe9vdCjq+ SZ78XBHXNqz0VoSkmTU1SeJzQMMT7IcN+6uIVXOblIpT2cIbxElBGt36TxNLwTxxLd8B LOO1G+OJszGgP8VmU5BgH9C0UXBZ2cTTEmbG24SFrTcHbbWeZB/zy6XtkKhVUn/UVX0c HinmwlCt7S2kVwCOMFDZpxFUI4D9kEpgDx5G87RPIvwIJ5B/h5dDGnYx1FL1Bp42Ph1G bDmA== X-Gm-Message-State: AOAM533516gOW+kHLxOnmryrKOazyX6wCBScLICCHBHIeMKC14HN1oso EQxZhJBIP8vZxBKom28QYwLdnzgDCe8YHg== X-Google-Smtp-Source: ABdhPJwaV+QUa8xQ6sTr1dkn+CDVLI3ZjNVlDhtsZalRL0ZmsH5ymTnB73P1thQ1xX76iTIr+5mcdQ== X-Received: by 2002:adf:e19a:0:b0:210:157c:7b3c with SMTP id az26-20020adfe19a000000b00210157c7b3cmr13369355wrb.121.1653899579849; Mon, 30 May 2022 01:32:59 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id a13-20020a05600c348d00b0039754d1d327sm9536328wmq.13.2022.05.30.01.32.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 May 2022 01:32:59 -0700 (PDT) Date: Mon, 30 May 2022 08:32:58 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [Ada] Simplify construction of a path to file Message-ID: <20220530083258.GA211034@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="HlL+5n6rz5pIUxbD" Content-Disposition: inline X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 May 2022 08:33:07 -0000 --HlL+5n6rz5pIUxbD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Code cleanup; semantics is unaffected. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * osint.adb (Locate_File): Change variable to constant and initialize it by concatenation of directory, file name and NUL. --HlL+5n6rz5pIUxbD Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/osint.adb b/gcc/ada/osint.adb --- a/gcc/ada/osint.adb +++ b/gcc/ada/osint.adb @@ -1886,13 +1886,13 @@ package body Osint is end if; declare - Full_Name : String (1 .. Dir_Name'Length + Name'Length + 1); + Full_Name : + constant String (1 .. Dir_Name'Length + Name'Length + 1) := + Dir_Name.all & Name & ASCII.NUL; + -- Use explicit bounds, because Dir_Name might be a substring whose + -- 'First is not 1. begin - Full_Name (1 .. Dir_Name'Length) := Dir_Name.all; - Full_Name (Dir_Name'Length + 1 .. Full_Name'Last - 1) := Name; - Full_Name (Full_Name'Last) := ASCII.NUL; - Attr.all := Unknown_Attributes; if not Is_Regular_File (Full_Name'Address, Attr) then --HlL+5n6rz5pIUxbD--