aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSheri Bernstein <bernstein@adacore.com>2023-11-17 22:14:48 +0000
committerMarc Poulhiès <poulhies@adacore.com>2023-11-30 11:12:48 +0100
commitdab7e3430e76c7f23839e112f1c9676383263256 (patch)
treef13873f69318c790fbcb3c73512c5262409bb0dc
parentce5572d4b8b391657f050b783f0a65471cd36ad2 (diff)
downloadgcc-dab7e3430e76c7f23839e112f1c9676383263256.zip
gcc-dab7e3430e76c7f23839e112f1c9676383263256.tar.gz
gcc-dab7e3430e76c7f23839e112f1c9676383263256.tar.bz2
ada: Remove GNATcheck violations
Remove GNATcheck violations by refactoring code and also using pragma Annotate to exempt them. gcc/ada/ * libgnat/i-cstrin.adb (Free): Rewrite code so there is only one return, to remove Improper_Returns violation. (Position_Of_Nul): Add pragma to exempt Improper_Returns violation. (To_Chars_Ptr): Likewise. (Value): Likewise
-rw-r--r--gcc/ada/libgnat/i-cstrin.adb24
1 files changed, 19 insertions, 5 deletions
diff --git a/gcc/ada/libgnat/i-cstrin.adb b/gcc/ada/libgnat/i-cstrin.adb
index afbac72..1eb2865 100644
--- a/gcc/ada/libgnat/i-cstrin.adb
+++ b/gcc/ada/libgnat/i-cstrin.adb
@@ -92,12 +92,10 @@ is
procedure Free (Item : in out chars_ptr) is
begin
- if Item = Null_Ptr then
- return;
+ if Item /= Null_Ptr then
+ Memory_Free (Item);
+ Item := Null_Ptr;
end if;
-
- Memory_Free (Item);
- Item := Null_Ptr;
end Free;
--------------------
@@ -187,6 +185,8 @@ is
function Position_Of_Nul (Into : char_array) return size_t is
begin
+ pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+ "early returns for performance");
for J in Into'Range loop
if Into (J) = nul then
return J;
@@ -194,6 +194,8 @@ is
end loop;
return Into'Last + 1;
+
+ pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
end Position_Of_Nul;
------------
@@ -226,6 +228,8 @@ is
Nul_Check : Boolean := False) return chars_ptr
is
begin
+ pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+ "early returns for performance");
if Item = null then
return Null_Ptr;
elsif Nul_Check
@@ -235,6 +239,8 @@ is
else
return To_chars_ptr (Item (Item'First)'Address);
end if;
+
+ pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
end To_Chars_Ptr;
------------
@@ -302,6 +308,8 @@ is
Length : size_t) return char_array
is
begin
+ pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+ "early returns for performance");
if Item = Null_Ptr then
raise Dereference_Error;
end if;
@@ -328,6 +336,8 @@ is
return Result;
end;
+
+ pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
end Value;
function Value (Item : chars_ptr) return String is
@@ -339,6 +349,8 @@ is
Result : char_array (0 .. Length);
begin
+ pragma Annotate (Gnatcheck, Exempt_On, "Improper_Returns",
+ "early returns for performance");
-- As per AI-00177, this is equivalent to:
-- To_Ada (Value (Item, Length) & nul);
@@ -357,6 +369,8 @@ is
Result (Length) := nul;
return To_Ada (Result);
+
+ pragma Annotate (Gnatcheck, Exempt_Off, "Improper_Returns");
end Value;
end Interfaces.C.Strings;