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-4674] [Ada] Reference in Unbounded_String is almost never null Date: Mon, 25 Oct 2021 15:08:25 +0000 (GMT) [thread overview] Message-ID: <20211025150825.F39093858010@sourceware.org> (raw) https://gcc.gnu.org/g:98f939e9c98403636f10168be568bb9b800aac41 commit r12-4674-g98f939e9c98403636f10168be568bb9b800aac41 Author: Piotr Trojanek <trojanek@adacore.com> Date: Tue Jun 15 23:32:51 2021 +0200 [Ada] Reference in Unbounded_String is almost never null gcc/ada/ * libgnat/a-strunb.ads (Unbounded_String): Reference is never null. * libgnat/a-strunb.adb (Finalize): Copy reference while it needs to be deallocated. Diff: --- gcc/ada/libgnat/a-strunb.adb | 10 ++++++++-- gcc/ada/libgnat/a-strunb.ads | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gcc/ada/libgnat/a-strunb.adb b/gcc/ada/libgnat/a-strunb.adb index 4727f965486..0d62e4b379f 100644 --- a/gcc/ada/libgnat/a-strunb.adb +++ b/gcc/ada/libgnat/a-strunb.adb @@ -505,8 +505,14 @@ package body Ada.Strings.Unbounded is -- Note: Don't try to free statically allocated null string if Object.Reference /= Null_String'Access then - Deallocate (Object.Reference); - Object.Reference := Null_Unbounded_String.Reference; + declare + Reference_Copy : 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); + Object.Reference := Null_Unbounded_String.Reference; + end; Object.Last := 0; end if; end Finalize; diff --git a/gcc/ada/libgnat/a-strunb.ads b/gcc/ada/libgnat/a-strunb.ads index b3050fdb5a3..2f5bd948f3b 100644 --- a/gcc/ada/libgnat/a-strunb.ads +++ b/gcc/ada/libgnat/a-strunb.ads @@ -746,8 +746,8 @@ private renames To_Unbounded_String; type Unbounded_String is new AF.Controlled with record - Reference : String_Access := Null_String'Access; - Last : Natural := 0; + Reference : not null String_Access := Null_String'Access; + Last : Natural := 0; end record with Put_Image => Put_Image; procedure Put_Image
reply other threads:[~2021-10-25 15:08 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=20211025150825.F39093858010@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).