* [Ada] Complete contracts of Interfaces.C.Strings subprograms
@ 2022-06-02 9:08 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-06-02 9:08 UTC (permalink / raw)
To: gcc-patches; +Cc: Joffrey Huguet
[-- Attachment #1: Type: text/plain, Size: 208 bytes --]
This patch adds preconditions to Update procedures, to protect from
Update_Error propagations.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* libgnat/i-cstrin.ads (Update): Add precondition.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1186 bytes --]
diff --git a/gcc/ada/libgnat/i-cstrin.ads b/gcc/ada/libgnat/i-cstrin.ads
--- a/gcc/ada/libgnat/i-cstrin.ads
+++ b/gcc/ada/libgnat/i-cstrin.ads
@@ -36,7 +36,8 @@
-- Preconditions in this unit are meant for analysis only, not for run-time
-- checking, so that the expected exceptions are raised. This is enforced by
-- setting the corresponding assertion policy to Ignore. These preconditions
--- do not protect against Storage_Error.
+-- protect from Dereference_Error and Update_Error, but not from
+-- Storage_Error.
pragma Assertion_Policy (Pre => Ignore);
@@ -117,7 +118,9 @@ is
Chars : char_array;
Check : Boolean := True)
with
- Pre => Item /= Null_Ptr,
+ Pre =>
+ Item /= Null_Ptr
+ and then (if Check then Offset <= Strlen (Item) - Chars'Length),
Global => (In_Out => C_Memory);
procedure Update
@@ -126,7 +129,9 @@ is
Str : String;
Check : Boolean := True)
with
- Pre => Item /= Null_Ptr,
+ Pre =>
+ Item /= Null_Ptr
+ and then (if Check then Offset <= Strlen (Item) - Str'Length),
Global => (In_Out => C_Memory);
Update_Error : exception;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-02 9:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02 9:08 [Ada] Complete contracts of Interfaces.C.Strings subprograms Pierre-Marie de Rodat
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).