]> gcc.gnu.org Git - gcc.git/commitdiff
[Ada] Fix preconditions of Interfaces.C.Strings
authorJoffrey Huguet <huguet@adacore.com>
Thu, 12 May 2022 09:53:54 +0000 (11:53 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 2 Jun 2022 09:06:40 +0000 (09:06 +0000)
Preconditions of Update procedures were always true when Offset was 0.
The changes enable to protect from Update_Error when Offset is 0.

gcc/ada/

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

gcc/ada/libgnat/i-cstrin.ads

index faad7a0b73b5a2f278186c9b405dc535d1604885..12fa3012ff0fb6a17dc1491aa5122739fa27acd2 100644 (file)
@@ -120,7 +120,10 @@ is
    with
      Pre    =>
        Item /= Null_Ptr
-         and then (if Check then Offset <= Strlen (Item) - Chars'Length),
+         and then
+      (if Check then
+         Strlen (Item) <= size_t'Last - Offset
+           and then Strlen (Item) + Offset <= Chars'Length),
      Global => (In_Out => C_Memory);
 
    procedure Update
@@ -131,7 +134,10 @@ is
    with
      Pre    =>
        Item /= Null_Ptr
-         and then (if Check then Offset <= Strlen (Item) - Str'Length),
+         and then
+      (if Check then
+         Strlen (Item) <= size_t'Last - Offset
+           and then Strlen (Item) + Offset <= Str'Length),
      Global => (In_Out => C_Memory);
 
    Update_Error : exception;
This page took 0.061575 seconds and 5 git commands to generate.