]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix precondition in Interfaces.C.Strings
authorJoffrey Huguet <huguet@adacore.com>
Wed, 6 Dec 2023 11:04:51 +0000 (12:04 +0100)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 9 Jan 2024 13:13:30 +0000 (14:13 +0100)
The precondition of both Update procedures in Interfaces.C.Strings were
incorrect. This patch fixes this.

gcc/ada/

* libgnat/i-cstrin.ads (Update): Fix precondition.

gcc/ada/libgnat/i-cstrin.ads

index 9f1577f5e14c0a5209c37d4888bbbf20a5224330..3f55ddfbdc55df21b89be5726574789a25ff9889 100644 (file)
@@ -121,8 +121,9 @@ is
    with
      Pre    =>
        Item /= Null_Ptr
-         and then Strlen (Item) <= size_t'Last - Offset
-         and then Strlen (Item) + Offset <= Chars'Length,
+         and then (Chars'First /= 0 or else Chars'Last /= size_t'Last)
+         and then Chars'Length <= size_t'Last - Offset
+         and then Chars'Length + Offset <= Strlen (Item),
      Global => (In_Out => C_Memory);
 
    procedure Update
@@ -133,8 +134,8 @@ is
    with
      Pre    =>
        Item /= Null_Ptr
-         and then Strlen (Item) <= size_t'Last - Offset
-         and then Strlen (Item) + Offset <= Str'Length,
+         and then Str'Length <= size_t'Last - Offset
+         and then Str'Length + Offset <= Strlen (Item),
      Global => (In_Out => C_Memory);
 
    Update_Error : exception;