From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Joffrey Huguet <huguet@adacore.com>
Subject: [Ada] Complete contracts of Interfaces.C.Strings subprograms
Date: Thu, 2 Jun 2022 09:08:51 +0000 [thread overview]
Message-ID: <20220602090851.GA1010590@adacore.com> (raw)
[-- 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;
reply other threads:[~2022-06-02 9:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220602090851.GA1010590@adacore.com \
--to=derodat@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=huguet@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).