aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey Huguet <huguet@adacore.com>2022-05-12 11:53:54 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2022-06-02 09:06:40 +0000
commitcfd2262668862167cbe102ffbe87f127599be7a8 (patch)
tree33873ae802ab59d0ddc0699acd580e62209357cd
parent5987f43412766ef5fc7cd56b4a2cb6a44a3940ba (diff)
downloadgcc-cfd2262668862167cbe102ffbe87f127599be7a8.zip
gcc-cfd2262668862167cbe102ffbe87f127599be7a8.tar.gz
gcc-cfd2262668862167cbe102ffbe87f127599be7a8.tar.bz2
[Ada] Fix preconditions of Interfaces.C.Strings
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.
-rw-r--r--gcc/ada/libgnat/i-cstrin.ads10
1 files changed, 8 insertions, 2 deletions
diff --git a/gcc/ada/libgnat/i-cstrin.ads b/gcc/ada/libgnat/i-cstrin.ads
index faad7a0..12fa301 100644
--- a/gcc/ada/libgnat/i-cstrin.ads
+++ b/gcc/ada/libgnat/i-cstrin.ads
@@ -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;