[COMMITTED] ada: Remove GNATcheck violations
Checks
Commit Message
From: Sheri Bernstein <bernstein@adacore.com>
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
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/libgnat/i-cstrin.adb | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
@@ -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;