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-5025] [Ada] Reference in Unbounded_String is almost never null Date: Tue, 9 Nov 2021 09:46:15 +0000 (GMT) [thread overview] Message-ID: <20211109094615.79ABF3858000@sourceware.org> (raw) https://gcc.gnu.org/g:f4665dc4fb511a40a104f1986488861fee8b24f7 commit r12-5025-gf4665dc4fb511a40a104f1986488861fee8b24f7 Author: Piotr Trojanek <trojanek@adacore.com> Date: Wed Oct 27 10:33:32 2021 +0200 [Ada] Reference in Unbounded_String is almost never null gcc/ada/ * libgnat/a-strunb.adb (Deallocate): Rename Reference_Copy to Old, to make the code similar to other routines in this package. (Realloc_For_Chunk): Use a temporary, deallocate the previous string using a null-allowing copy of the string reference. Diff: --- gcc/ada/libgnat/a-strunb.adb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gcc/ada/libgnat/a-strunb.adb b/gcc/ada/libgnat/a-strunb.adb index 0d62e4b379f..b0e455b9edb 100644 --- a/gcc/ada/libgnat/a-strunb.adb +++ b/gcc/ada/libgnat/a-strunb.adb @@ -506,11 +506,11 @@ package body Ada.Strings.Unbounded is if Object.Reference /= Null_String'Access then declare - Reference_Copy : String_Access := Object.Reference; + Old : String_Access := Object.Reference; -- The original reference cannot be null, so we must create a -- copy which will become null when deallocated. begin - Deallocate (Reference_Copy); + Deallocate (Old); Object.Reference := Null_Unbounded_String.Reference; end; Object.Last := 0; @@ -833,9 +833,13 @@ package body Ada.Strings.Unbounded is Tmp : constant String_Access := new String (1 .. New_Rounded_Up_Size); + Old : String_Access := Source.Reference; + -- The original reference cannot be null, so we must create a copy + -- which will become null when deallocated. + begin Tmp (1 .. Source.Last) := Source.Reference (1 .. Source.Last); - Free (Source.Reference); + Free (Old); Source.Reference := Tmp; end; end if;
reply other threads:[~2021-11-09 9:46 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=20211109094615.79ABF3858000@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: linkBe 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).