aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2021-10-27 10:33:32 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2021-11-09 09:44:48 +0000
commitf4665dc4fb511a40a104f1986488861fee8b24f7 (patch)
tree9d42d051fb77340faa716411974bf06426bcd75d
parentadc9410f95e3712f3f2fc4fe0e4a356af605fcd3 (diff)
downloadgcc-f4665dc4fb511a40a104f1986488861fee8b24f7.zip
gcc-f4665dc4fb511a40a104f1986488861fee8b24f7.tar.gz
gcc-f4665dc4fb511a40a104f1986488861fee8b24f7.tar.bz2
[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.
-rw-r--r--gcc/ada/libgnat/a-strunb.adb10
1 files changed, 7 insertions, 3 deletions
diff --git a/gcc/ada/libgnat/a-strunb.adb b/gcc/ada/libgnat/a-strunb.adb
index 0d62e4b..b0e455b 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;