public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-2119] [Ada] Use bounded string buffer in Get_Unit_Name
Date: Wed,  7 Jul 2021 16:26:00 +0000 (GMT)	[thread overview]
Message-ID: <20210707162600.B3319396DC3D@sourceware.org> (raw)

https://gcc.gnu.org/g:768f69696a054a0709b114d3ad3d73265daf115d

commit r12-2119-g768f69696a054a0709b114d3ad3d73265daf115d
Author: Piotr Trojanek <trojanek@adacore.com>
Date:   Tue May 11 12:16:14 2021 +0200

    [Ada] Use bounded string buffer in Get_Unit_Name
    
    gcc/ada/
    
            * uname.adb (Get_Unit_Name): Simplify with a bounded string
            buffer; also, this addresses a ??? comment about the max length
            being exceeded.

Diff:
---
 gcc/ada/uname.adb | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/gcc/ada/uname.adb b/gcc/ada/uname.adb
index 23911802a6f..18cb6d1a329 100644
--- a/gcc/ada/uname.adb
+++ b/gcc/ada/uname.adb
@@ -177,13 +177,8 @@ package body Uname is
 
    function Get_Unit_Name (N : Node_Id) return Unit_Name_Type is
 
-      Unit_Name_Buffer : String (1 .. Hostparm.Max_Name_Length);
-      --  Buffer used to build name of unit. Note that we cannot use the
-      --  Name_Buffer in package Name_Table because we use it to read
-      --  component names.
-
-      Unit_Name_Length : Natural := 0;
-      --  Length of name stored in Unit_Name_Buffer
+      Unit_Name_Buffer : Bounded_String;
+      --  Buffer used to build name of unit
 
       Node : Node_Id;
       --  Program unit node
@@ -206,9 +201,7 @@ package body Uname is
 
       procedure Add_Char (C : Character) is
       begin
-         --  Should really check for max length exceeded here???
-         Unit_Name_Length := Unit_Name_Length + 1;
-         Unit_Name_Buffer (Unit_Name_Length) := C;
+         Append (Unit_Name_Buffer, C);
       end Add_Char;
 
       --------------
@@ -217,11 +210,7 @@ package body Uname is
 
       procedure Add_Name (Name : Name_Id) is
       begin
-         Get_Name_String (Name);
-
-         for J in 1 .. Name_Len loop
-            Add_Char (Name_Buffer (J));
-         end loop;
+         Append (Unit_Name_Buffer, Name);
       end Add_Name;
 
       -------------------
@@ -414,11 +403,7 @@ package body Uname is
             raise Program_Error;
       end case;
 
-      Name_Buffer (1 .. Unit_Name_Length) :=
-        Unit_Name_Buffer (1 .. Unit_Name_Length);
-      Name_Len := Unit_Name_Length;
-      return Name_Find;
-
+      return Name_Find (Unit_Name_Buffer);
    end Get_Unit_Name;
 
    --------------------------


                 reply	other threads:[~2021-07-07 16:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210707162600.B3319396DC3D@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).