public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [COMMITTED] ada: Fix precondition in Interfaces.C.Strings
@ 2024-01-09 13:15 Marc Poulhiès
  0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2024-01-09 13:15 UTC (permalink / raw)
  To: gcc-patches; +Cc: Joffrey Huguet

From: Joffrey Huguet <huguet@adacore.com>

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.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/i-cstrin.ads | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/libgnat/i-cstrin.ads b/gcc/ada/libgnat/i-cstrin.ads
index 9f1577f5e14..3f55ddfbdc5 100644
--- a/gcc/ada/libgnat/i-cstrin.ads
+++ b/gcc/ada/libgnat/i-cstrin.ads
@@ -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;
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-09 13:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-09 13:15 [COMMITTED] ada: Fix precondition in Interfaces.C.Strings Marc Poulhiès

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).