aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/libgnat
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@adacore.com>2019-12-12 14:01:03 +0100
committerPierre-Marie de Rodat <derodat@adacore.com>2020-06-02 04:58:05 -0400
commita6b13d324fa2d83538e2c733906ced7b000209ac (patch)
treeda57150775778fc8e4b3770d2b80fd68e49c4c66 /gcc/ada/libgnat
parent5c726f3e42e227fdca32289e99b815988c40481a (diff)
downloadgcc-a6b13d324fa2d83538e2c733906ced7b000209ac.zip
gcc-a6b13d324fa2d83538e2c733906ced7b000209ac.tar.gz
gcc-a6b13d324fa2d83538e2c733906ced7b000209ac.tar.bz2
[Ada] Address potentially uninitialized variables and dead code
2020-06-02 Arnaud Charlet <charlet@adacore.com> gcc/ada/ * bcheck.adb, binde.adb, bindo-diagnostics.adb, checks.adb, exp_aggr.adb, exp_ch3.adb, exp_ch4.adb, exp_ch7.adb, exp_ch9.adb, gnatname.adb, sem_case.adb, sem_ch13.adb, sem_ch5.adb, sem_prag.adb, sem_util.adb, uintp.adb, urealp.adb, xoscons.adb, xr_tabls.adb, xref_lib.adb: Initialize objects more explicitly and add corresponding assertions. Remove dead code. Also add a few Annotate pragmas to help static analysis. * libgnat/a-caldel.adb, libgnat/a-calend.adb, libgnat/a-ngcoty.adb, libgnat/a-ngelfu.adb, libgnat/a-ngrear.adb, libgnat/a-strfix.adb, libgnat/g-calend.adb, libgnat/g-catiio.adb, libgnat/g-comlin.adb, libgnat/g-debpoo.adb, libgnat/g-dirope.adb, libgnat/g-hesorg.adb, libgnat/g-pehage.adb, libgnat/g-socket.adb, libgnat/i-cobol.adb, libgnat/s-dwalin.adb, libgnat/s-dwalin.ads, libgnat/s-fatgen.adb, libgnat/s-gearop.adb, libgnat/s-genbig.adb, libgnat/s-imgrea.adb, libgnat/s-os_lib.adb, libgnat/s-rannum.adb, libgnat/s-regpat.adb, libgnat/s-trasym__dwarf.adb, libgnat/s-valrea.adb: Ditto.
Diffstat (limited to 'gcc/ada/libgnat')
-rw-r--r--gcc/ada/libgnat/a-caldel.adb2
-rw-r--r--gcc/ada/libgnat/a-calend.adb14
-rw-r--r--gcc/ada/libgnat/a-ngcoty.adb10
-rw-r--r--gcc/ada/libgnat/a-ngelfu.adb2
-rw-r--r--gcc/ada/libgnat/a-ngrear.adb2
-rw-r--r--gcc/ada/libgnat/a-strfix.adb4
-rw-r--r--gcc/ada/libgnat/g-calend.adb3
-rw-r--r--gcc/ada/libgnat/g-catiio.adb2
-rw-r--r--gcc/ada/libgnat/g-comlin.adb1
-rw-r--r--gcc/ada/libgnat/g-debpoo.adb1
-rw-r--r--gcc/ada/libgnat/g-dirope.adb2
-rw-r--r--gcc/ada/libgnat/g-hesorg.adb2
-rw-r--r--gcc/ada/libgnat/g-pehage.adb9
-rw-r--r--gcc/ada/libgnat/g-socket.adb13
-rw-r--r--gcc/ada/libgnat/i-cobol.adb5
-rw-r--r--gcc/ada/libgnat/s-dwalin.adb17
-rw-r--r--gcc/ada/libgnat/s-dwalin.ads2
-rw-r--r--gcc/ada/libgnat/s-fatgen.adb4
-rw-r--r--gcc/ada/libgnat/s-gearop.adb7
-rw-r--r--gcc/ada/libgnat/s-genbig.adb1
-rw-r--r--gcc/ada/libgnat/s-imgrea.adb5
-rw-r--r--gcc/ada/libgnat/s-os_lib.adb13
-rw-r--r--gcc/ada/libgnat/s-rannum.adb1
-rw-r--r--gcc/ada/libgnat/s-regpat.adb31
-rw-r--r--gcc/ada/libgnat/s-trasym__dwarf.adb2
-rw-r--r--gcc/ada/libgnat/s-valrea.adb12
26 files changed, 116 insertions, 51 deletions
diff --git a/gcc/ada/libgnat/a-caldel.adb b/gcc/ada/libgnat/a-caldel.adb
index b7cfefc..9244425 100644
--- a/gcc/ada/libgnat/a-caldel.adb
+++ b/gcc/ada/libgnat/a-caldel.adb
@@ -103,6 +103,8 @@ begin
-- this soft link, or this will be overridden during the elaboration of
-- System.Tasking.Initialization
+ pragma Annotate (CodePeer, Modified, SSL.Timed_Delay);
+
if SSL.Timed_Delay = null then
SSL.Timed_Delay := Timed_Delay_NT'Access;
end if;
diff --git a/gcc/ada/libgnat/a-calend.adb b/gcc/ada/libgnat/a-calend.adb
index 4cbfeff..219fd9a 100644
--- a/gcc/ada/libgnat/a-calend.adb
+++ b/gcc/ada/libgnat/a-calend.adb
@@ -435,18 +435,14 @@ is
if End_T < Leap_Second_Times (1) then
Elapsed_Leaps := 0;
Next_Leap := Leap_Second_Times (1);
- return;
elsif Start_T > Leap_Second_Times (Leap_Seconds_Count) then
Elapsed_Leaps := 0;
Next_Leap := End_Of_Time;
- return;
- end if;
-
- -- Perform the calculations only if the start date is within the leap
- -- second occurrences table.
- if Start_T <= Leap_Second_Times (Leap_Seconds_Count) then
+ else
+ -- Perform the calculations only if the start date is within the leap
+ -- second occurrences table.
-- 1 2 N - 1 N
-- +----+----+-- . . . --+-------+---+
@@ -480,9 +476,6 @@ is
end if;
Elapsed_Leaps := End_Index - Start_Index;
-
- else
- Elapsed_Leaps := 0;
end if;
end Cumulative_Leap_Seconds;
@@ -763,6 +756,7 @@ is
(Secs_T'Unchecked_Access,
Flag'Unchecked_Access,
Offset'Unchecked_Access);
+ pragma Annotate (CodePeer, Modified, Offset);
return Long_Integer (Offset);
end UTC_Time_Offset;
diff --git a/gcc/ada/libgnat/a-ngcoty.adb b/gcc/ada/libgnat/a-ngcoty.adb
index bece703..deb200b 100644
--- a/gcc/ada/libgnat/a-ngcoty.adb
+++ b/gcc/ada/libgnat/a-ngcoty.adb
@@ -66,11 +66,19 @@ package body Ada.Numerics.Generic_Complex_Types is
-- return false, the test can only be written thus.
if not (abs (X) <= R'Last) then
+ pragma Annotate
+ (CodePeer, Intentional,
+ "test always false", "test for infinity");
+
X := Scale**2 * ((Left.Re / Scale) * (Right.Re / Scale) -
(Left.Im / Scale) * (Right.Im / Scale));
end if;
if not (abs (Y) <= R'Last) then
+ pragma Annotate
+ (CodePeer, Intentional,
+ "test always false", "test for infinity");
+
Y := Scale**2 * ((Left.Re / Scale) * (Right.Im / Scale)
+ (Left.Im / Scale) * (Right.Re / Scale));
end if;
@@ -588,6 +596,7 @@ package body Ada.Numerics.Generic_Complex_Types is
exception
when Constraint_Error =>
+ pragma Assert (X.Re /= 0.0);
return R (Double (abs (X.Re))
* Sqrt (1.0 + (Double (X.Im) / Double (X.Re)) ** 2));
end;
@@ -602,6 +611,7 @@ package body Ada.Numerics.Generic_Complex_Types is
exception
when Constraint_Error =>
+ pragma Assert (X.Im /= 0.0);
return R (Double (abs (X.Im))
* Sqrt (1.0 + (Double (X.Re) / Double (X.Im)) ** 2));
end;
diff --git a/gcc/ada/libgnat/a-ngelfu.adb b/gcc/ada/libgnat/a-ngelfu.adb
index 71cd47b..3d49404 100644
--- a/gcc/ada/libgnat/a-ngelfu.adb
+++ b/gcc/ada/libgnat/a-ngelfu.adb
@@ -680,6 +680,8 @@ is
Z := G * G;
P := G * ((P2 * Z + P1) * Z + P0);
Q := ((Q3 * Z + Q2) * Z + Q1) * Z + Q0;
+
+ pragma Assert (Q /= P);
R := 0.5 + P / (Q - P);
R := Float_Type'Base'Scaling (R, Integer (XN) + 1);
diff --git a/gcc/ada/libgnat/a-ngrear.adb b/gcc/ada/libgnat/a-ngrear.adb
index 8418ec1..8348cb7 100644
--- a/gcc/ada/libgnat/a-ngrear.adb
+++ b/gcc/ada/libgnat/a-ngrear.adb
@@ -560,6 +560,8 @@ package body Ada.Numerics.Generic_Real_Arrays is
function Compute_Tan (P, H : Real) return Real is
(if Is_Tiny (P, Compared_To => H) then P / H
else Compute_Tan (Theta => H / (2.0 * P)));
+ pragma Annotate
+ (CodePeer, False_Positive, "divide by zero", "H, P /= 0");
function Sum_Strict_Upper (M : Square_Matrix) return Real;
-- Return the sum of all elements in the strict upper triangle of M
diff --git a/gcc/ada/libgnat/a-strfix.adb b/gcc/ada/libgnat/a-strfix.adb
index b8b5f42..1f94b86 100644
--- a/gcc/ada/libgnat/a-strfix.adb
+++ b/gcc/ada/libgnat/a-strfix.adb
@@ -192,6 +192,10 @@ package body Ada.Strings.Fixed is
elsif From not in Source'Range
or else Through > Source'Last
then
+ pragma Annotate
+ (CodePeer, False_Positive,
+ "test always false", "self fullfilling prophecy");
+
-- In most cases this raises an exception, but the case of deleting
-- a null string at the end of the current one is a special-case, and
-- reflects the equivalence with Replace_String (RM A.4.3 (86/3)).
diff --git a/gcc/ada/libgnat/g-calend.adb b/gcc/ada/libgnat/g-calend.adb
index d1d4b55..ab5bab3 100644
--- a/gcc/ada/libgnat/g-calend.adb
+++ b/gcc/ada/libgnat/g-calend.adb
@@ -352,6 +352,9 @@ package body GNAT.Calendar is
begin
timeval_to_duration (T, sec'Access, usec'Access);
+ pragma Annotate (CodePeer, Modified, sec);
+ pragma Annotate (CodePeer, Modified, usec);
+
return Duration (sec) + Duration (usec) / Micro;
end To_Duration;
diff --git a/gcc/ada/libgnat/g-catiio.adb b/gcc/ada/libgnat/g-catiio.adb
index dc2fa40..cc860ab 100644
--- a/gcc/ada/libgnat/g-catiio.adb
+++ b/gcc/ada/libgnat/g-catiio.adb
@@ -950,6 +950,8 @@ package body GNAT.Calendar.Time_IO is
when End_Of_Source_Reached
| Wrong_Syntax
=>
+ Time :=
+ Time_Of (Year_Number'First, Month_Number'First, Day_Number'First);
Success := False;
end Parse_ISO_8861_UTC;
diff --git a/gcc/ada/libgnat/g-comlin.adb b/gcc/ada/libgnat/g-comlin.adb
index ec057a9..bb553e9 100644
--- a/gcc/ada/libgnat/g-comlin.adb
+++ b/gcc/ada/libgnat/g-comlin.adb
@@ -537,6 +537,7 @@ package body GNAT.Command_Line is
P : Switch_Parameter_Type;
begin
+ Param := Parameter_None;
Index_In_Switches := 0;
Switch_Length := 0;
diff --git a/gcc/ada/libgnat/g-debpoo.adb b/gcc/ada/libgnat/g-debpoo.adb
index 52c0c50..ae2fb1c 100644
--- a/gcc/ada/libgnat/g-debpoo.adb
+++ b/gcc/ada/libgnat/g-debpoo.adb
@@ -1420,6 +1420,7 @@ package body GNAT.Debug_Pools is
begin
Valid := Is_Valid (Storage_Address);
+ Size_In_Storage_Elements := Storage_Count'First;
if Is_Valid (Storage_Address) then
declare
diff --git a/gcc/ada/libgnat/g-dirope.adb b/gcc/ada/libgnat/g-dirope.adb
index 9153c70..0fd7a24 100644
--- a/gcc/ada/libgnat/g-dirope.adb
+++ b/gcc/ada/libgnat/g-dirope.adb
@@ -352,6 +352,8 @@ package body GNAT.Directory_Operations is
begin
K := K + 1;
+ pragma Annotate (CodePeer, Modified, P);
+
if P = '%' or else Path (K) = '{' then
-- Set terminator character
diff --git a/gcc/ada/libgnat/g-hesorg.adb b/gcc/ada/libgnat/g-hesorg.adb
index fec6e9c..bf54874 100644
--- a/gcc/ada/libgnat/g-hesorg.adb
+++ b/gcc/ada/libgnat/g-hesorg.adb
@@ -45,6 +45,8 @@ package body GNAT.Heap_Sort_G is
-- from 2NlogN to NlogN.
procedure Sort (N : Natural) is
+ pragma Annotate (CodePeer, Skip_Analysis);
+ -- CodePeer is sometimes getting confused on this procedure
Max : Natural := N;
-- Current Max index in tree being sifted
diff --git a/gcc/ada/libgnat/g-pehage.adb b/gcc/ada/libgnat/g-pehage.adb
index 9b88256..a65dc85 100644
--- a/gcc/ada/libgnat/g-pehage.adb
+++ b/gcc/ada/libgnat/g-pehage.adb
@@ -622,6 +622,7 @@ package body GNAT.Perfect_Hash_Generators is
E := Get_Edges (J);
if Get_Graph (E.Y) = -1 then
+ pragma Assert (NK /= 0);
Set_Graph (E.Y, (E.Key - Get_Graph (X)) mod NK);
Assign (E.Y);
end if;
@@ -2201,6 +2202,8 @@ package body GNAT.Perfect_Hash_Generators is
-- in the position selection.
for J in S'Range loop
+ pragma Annotate (CodePeer, Modified, S (J));
+
if S (J).First = S (J).Last then
F := S (J).First;
L := S (J).Last;
@@ -2359,6 +2362,10 @@ package body GNAT.Perfect_Hash_Generators is
for P in 1 .. Last_Sel_Pos - 1 loop
if Max_Diff_Sel_Pos < Sel_Position (P) then
+ pragma Annotate
+ (CodePeer, False_Positive,
+ "test always false", "false positive?");
+
Sel_Position (P + 1 .. Last_Sel_Pos) :=
Sel_Position (P .. Last_Sel_Pos - 1);
Sel_Position (P) := Max_Diff_Sel_Pos;
@@ -2525,6 +2532,7 @@ package body GNAT.Perfect_Hash_Generators is
for J in 0 .. T1_Len - 1 loop
exit when Word (J + 1) = ASCII.NUL;
R := Get_Table (Table, J, Get_Used_Char (Word (J + 1)));
+ pragma Assert (NV /= 0);
S := (S + R) mod NV;
end loop;
@@ -2532,6 +2540,7 @@ package body GNAT.Perfect_Hash_Generators is
for J in 0 .. T1_Len - 1 loop
exit when Word (J + 1) = ASCII.NUL;
R := Get_Table (Table, J, 0);
+ pragma Assert (NV /= 0);
S := (S + R * Character'Pos (Word (J + 1))) mod NV;
end loop;
end case;
diff --git a/gcc/ada/libgnat/g-socket.adb b/gcc/ada/libgnat/g-socket.adb
index 6c65424..8f8c9d81 100644
--- a/gcc/ada/libgnat/g-socket.adb
+++ b/gcc/ada/libgnat/g-socket.adb
@@ -836,6 +836,7 @@ package body GNAT.Sockets is
-- the waiting task to resume its execution.
Res := Signalling_Fds.Create (Two_Fds'Access);
+ pragma Annotate (CodePeer, Modified, Two_Fds);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
@@ -886,6 +887,7 @@ package body GNAT.Sockets is
((if Family = Family_Unspec then Default_Socket_Pair_Family
else Families (Family)),
Modes (Mode), Levels (Level), Pair'Access);
+ pragma Annotate (CodePeer, Modified, Pair);
if Res = Failure then
Raise_Socket_Error (Socket_Errno);
@@ -957,8 +959,12 @@ package body GNAT.Sockets is
if Item.Last /= No_Socket then
Get_Socket_From_Set
(Item.Set'Access, Last => L'Access, Socket => S'Access);
+ pragma Annotate (CodePeer, Modified, L);
+ pragma Annotate (CodePeer, Modified, S);
+
Item.Last := Socket_Type (L);
Socket := Socket_Type (S);
+
else
Socket := No_Socket;
end if;
@@ -2921,8 +2927,7 @@ package body GNAT.Sockets is
-- To_Int --
------------
- function To_Int (F : Request_Flag_Type) return C.int
- is
+ function To_Int (F : Request_Flag_Type) return C.int is
Current : Request_Flag_Type := F;
Result : C.int := 0;
@@ -2932,6 +2937,10 @@ package body GNAT.Sockets is
if Current mod 2 /= 0 then
if Flags (J) = -1 then
+ pragma Annotate
+ (CodePeer, False_Positive,
+ "test always false", "self fulfilling prophecy");
+
Raise_Socket_Error (SOSC.EOPNOTSUPP);
end if;
diff --git a/gcc/ada/libgnat/i-cobol.adb b/gcc/ada/libgnat/i-cobol.adb
index 807a3a1..6caa351 100644
--- a/gcc/ada/libgnat/i-cobol.adb
+++ b/gcc/ada/libgnat/i-cobol.adb
@@ -240,11 +240,6 @@ package body Interfaces.COBOL is
(COBOL_Character'Pos (K) -
COBOL_Character'Pos (COBOL_Digits'First));
- elsif K in COBOL_Plus_Digits then
- Result := Result * 10 +
- (COBOL_Character'Pos (K) -
- COBOL_Character'Pos (COBOL_Plus_Digits'First));
-
elsif K in COBOL_Minus_Digits then
Result := Result * 10 +
(COBOL_Character'Pos (K) -
diff --git a/gcc/ada/libgnat/s-dwalin.adb b/gcc/ada/libgnat/s-dwalin.adb
index 5307eae..6745953 100644
--- a/gcc/ada/libgnat/s-dwalin.adb
+++ b/gcc/ada/libgnat/s-dwalin.adb
@@ -440,6 +440,10 @@ package body System.Dwarf_Lines is
or else Info_Sec = Null_Section
or else Aranges_Sec = Null_Section
then
+ pragma Annotate
+ (CodePeer, False_Positive,
+ "test always true", "codepeer got confused");
+
C.Has_Debug := False;
return;
end if;
@@ -883,6 +887,7 @@ package body System.Dwarf_Lines is
Success : out Boolean)
is
begin
+ Info_Offset := 0;
Seek (C.Aranges, 0);
while Tell (C.Aranges) < Length (C.Aranges) loop
@@ -905,6 +910,7 @@ package body System.Dwarf_Lines is
end;
end loop;
end loop;
+
Success := False;
end Aranges_Lookup;
@@ -1028,6 +1034,7 @@ package body System.Dwarf_Lines is
Has_Child : uint8;
pragma Unreferenced (Has_Child);
begin
+ Line_Offset := 0;
Success := False;
Seek (C.Info, Info_Offset);
@@ -1119,7 +1126,8 @@ package body System.Dwarf_Lines is
Version : uint16;
Sz : uint8;
begin
- Success := False;
+ Success := False;
+ Info_Offset := 0;
Read_Initial_Length (C.Aranges, Unit_Length, Is64);
@@ -1407,6 +1415,7 @@ package body System.Dwarf_Lines is
Success : Boolean;
Done : Boolean;
S : Object_Symbol;
+
begin
-- Initialize result
Dir_Name := null;
@@ -1422,6 +1431,8 @@ package body System.Dwarf_Lines is
begin
First := C.Cache'First;
Last := C.Cache'Last;
+ Mid := First;
+
while First <= Last loop
Mid := First + (Last - First) / 2;
if Addr_Off < C.Cache (Mid).First then
@@ -1432,6 +1443,7 @@ package body System.Dwarf_Lines is
exit;
end if;
end loop;
+
if Addr_Off >= C.Cache (Mid).First
and then Addr_Off < C.Cache (Mid).First + C.Cache (Mid).Size
then
@@ -1474,6 +1486,7 @@ package body System.Dwarf_Lines is
C.Next_Prologue := 0;
Initialize_State_Machine (C);
Parse_Prologue (C);
+ Previous_Row.Line := 0;
-- Advance to the first entry
@@ -1535,7 +1548,7 @@ package body System.Dwarf_Lines is
(Cin : Dwarf_Context;
Traceback : AET.Tracebacks_Array;
Suppress_Hex : Boolean;
- Symbol_Found : in out Boolean;
+ Symbol_Found : out Boolean;
Res : in out System.Bounded_Strings.Bounded_String)
is
use Ada.Characters.Handling;
diff --git a/gcc/ada/libgnat/s-dwalin.ads b/gcc/ada/libgnat/s-dwalin.ads
index 297fd8e..cfde1c6 100644
--- a/gcc/ada/libgnat/s-dwalin.ads
+++ b/gcc/ada/libgnat/s-dwalin.ads
@@ -93,7 +93,7 @@ package System.Dwarf_Lines is
(Cin : Dwarf_Context;
Traceback : AET.Tracebacks_Array;
Suppress_Hex : Boolean;
- Symbol_Found : in out Boolean;
+ Symbol_Found : out Boolean;
Res : in out System.Bounded_Strings.Bounded_String);
-- Generate a string for a traceback suitable for displaying to the user.
-- If one or more symbols are found, Symbol_Found is set to True. This
diff --git a/gcc/ada/libgnat/s-fatgen.adb b/gcc/ada/libgnat/s-fatgen.adb
index 93237fb..481d672 100644
--- a/gcc/ada/libgnat/s-fatgen.adb
+++ b/gcc/ada/libgnat/s-fatgen.adb
@@ -219,6 +219,10 @@ package body System.Fat_Gen is
Ax := Ax * R_Power (Expbits'Last);
Ex := Ex - Log_Power (Expbits'Last);
end loop;
+ pragma Annotate
+ (CodePeer, Intentional,
+ "test always false",
+ "expected for some instantiations");
-- Rad ** -64 <= Ax < 1
diff --git a/gcc/ada/libgnat/s-gearop.adb b/gcc/ada/libgnat/s-gearop.adb
index 4064571..166b04b 100644
--- a/gcc/ada/libgnat/s-gearop.adb
+++ b/gcc/ada/libgnat/s-gearop.adb
@@ -240,6 +240,8 @@ package body System.Generic_Array_Operations is
for J in N'Range (2) loop
N (Row - M'First (1) + N'First (1), J) :=
N (Row - M'First (1) + N'First (1), J) / Scale;
+ pragma Annotate
+ (CodePeer, False_Positive, "divide by zero", "Scale /= 0");
end loop;
end Divide_Row;
@@ -602,6 +604,9 @@ package body System.Generic_Array_Operations is
end if;
elsif X > Real'Base'Last then
+ pragma Annotate
+ (CodePeer, Intentional,
+ "test always false", "test for infinity");
-- X is infinity, which is its own square root
@@ -627,6 +632,8 @@ package body System.Generic_Array_Operations is
-- of precision.
for J in 1 .. 8 loop
+ pragma Assert (Root /= 0.0);
+
Next := (Root + X / Root) / 2.0;
exit when Root = Next;
Root := Next;
diff --git a/gcc/ada/libgnat/s-genbig.adb b/gcc/ada/libgnat/s-genbig.adb
index 0a92dfb..69d284f 100644
--- a/gcc/ada/libgnat/s-genbig.adb
+++ b/gcc/ada/libgnat/s-genbig.adb
@@ -733,6 +733,7 @@ package body System.Generic_Bignums is
ND := 0;
for J in 1 .. X.Len loop
ND := Base * ND + DD (X.D (J));
+ pragma Assert (Div /= 0);
Result (J) := SD (ND / Div);
ND := ND rem Div;
end loop;
diff --git a/gcc/ada/libgnat/s-imgrea.adb b/gcc/ada/libgnat/s-imgrea.adb
index 467c482..46cacd0 100644
--- a/gcc/ada/libgnat/s-imgrea.adb
+++ b/gcc/ada/libgnat/s-imgrea.adb
@@ -289,6 +289,8 @@ package body System.Img_Real is
-- What we are looking for is a power of ten to divide X by
-- so that the result lies within the required range.
+ pragma Assert (Powten (Maxpow) /= 0.0);
+
loop
XP := X / Powten (Maxpow);
exit when XP < Powten (S) or else Scale > Maxscaling;
@@ -490,6 +492,9 @@ package body System.Img_Real is
-- an infinite value, so we print Inf.
if V > Long_Long_Float'Last then
+ pragma Annotate
+ (CodePeer, Intentional, "test always true", "test for infinity");
+
Set ('+');
Set ('I');
Set ('n');
diff --git a/gcc/ada/libgnat/s-os_lib.adb b/gcc/ada/libgnat/s-os_lib.adb
index 258cd64..28fbbf3 100644
--- a/gcc/ada/libgnat/s-os_lib.adb
+++ b/gcc/ada/libgnat/s-os_lib.adb
@@ -574,14 +574,15 @@ package body System.OS_Lib is
-- touch destination file at all.
From := Open_Read (Name, Binary);
- if From /= Invalid_FD then
+
+ if From = Invalid_FD then
+ Success := False;
+ else
To := Open_Read_Write (Pathname, Binary);
+ Lseek (To, 0, Seek_End);
+ Copy (From, To);
end if;
- Lseek (To, 0, Seek_End);
-
- Copy (From, To);
-
-- Appending to directory, not allowed
elsif Is_Directory (Pathname) then
@@ -1999,6 +2000,8 @@ package body System.OS_Lib is
-- If the string ends with \, double it
+ pragma Annotate (CodePeer, Modified, Res (J - 1));
+
if Res (J - 1) = '\' then
Res (J) := '\';
J := J + 1;
diff --git a/gcc/ada/libgnat/s-rannum.adb b/gcc/ada/libgnat/s-rannum.adb
index 0590313..1aa755c 100644
--- a/gcc/ada/libgnat/s-rannum.adb
+++ b/gcc/ada/libgnat/s-rannum.adb
@@ -295,6 +295,7 @@ is
K : Bit_Count; -- Next decrement to exponent
begin
+ K := 0;
Mantissa := Random (Gen) / 2**Extra_Bits;
R := Unsigned_32 (Mantissa mod 2**Extra_Bits);
R_Bits := Extra_Bits;
diff --git a/gcc/ada/libgnat/s-regpat.adb b/gcc/ada/libgnat/s-regpat.adb
index ae69f47..69fe150 100644
--- a/gcc/ada/libgnat/s-regpat.adb
+++ b/gcc/ada/libgnat/s-regpat.adb
@@ -1460,19 +1460,9 @@ package body System.Regpat is
and then Expression (Parse_Pos + 1) /= ']'
then
Parse_Pos := Parse_Pos + 1;
-
- -- Do we have a range like '\d-a' and '[:space:]-a'
- -- which is not a real range
-
- if Named_Class /= ANYOF_NONE then
- Set_In_Class (Bitmap, '-');
- else
- In_Range := True;
- end if;
-
+ In_Range := True;
else
Set_In_Class (Bitmap, Value);
-
end if;
-- Else in a character range
@@ -3275,13 +3265,13 @@ package body System.Regpat is
(IP : Pointer;
Max : Natural := Natural'Last) return Natural
is
- Scan : Natural := Input_Pos;
- Last : Natural;
- Op : constant Opcode := Opcode'Val (Character'Pos (Program (IP)));
- Count : Natural;
- C : Character;
- Is_First : Boolean := True;
- Bitmap : Character_Class;
+ Scan : Natural := Input_Pos;
+ Last : Natural;
+ Op : constant Opcode :=
+ Opcode'Val (Character'Pos (Program (IP)));
+ Count : Natural;
+ C : Character;
+ Bitmap : Character_Class;
begin
if Max = Natural'Last or else Scan + Max - 1 > Last_In_Data then
@@ -3324,10 +3314,7 @@ package body System.Regpat is
end loop;
when ANYOF =>
- if Is_First then
- Bitmap_Operand (Program, IP, Bitmap);
- Is_First := False;
- end if;
+ Bitmap_Operand (Program, IP, Bitmap);
while Scan <= Last
and then Get_From_Class (Bitmap, Data (Scan))
diff --git a/gcc/ada/libgnat/s-trasym__dwarf.adb b/gcc/ada/libgnat/s-trasym__dwarf.adb
index b116a10..9f96275 100644
--- a/gcc/ada/libgnat/s-trasym__dwarf.adb
+++ b/gcc/ada/libgnat/s-trasym__dwarf.adb
@@ -438,7 +438,7 @@ package body System.Traceback.Symbolic is
Suppress_Hex : Boolean;
Res : in out Bounded_String)
is
- Success : Boolean := False;
+ Success : Boolean;
begin
if Symbolic.Module_Name.Is_Supported then
Append (Res, '[');
diff --git a/gcc/ada/libgnat/s-valrea.adb b/gcc/ada/libgnat/s-valrea.adb
index 424ccd0..2ecc99b 100644
--- a/gcc/ada/libgnat/s-valrea.adb
+++ b/gcc/ada/libgnat/s-valrea.adb
@@ -92,8 +92,7 @@ package body System.Val_Real is
-- As_Digit --
--------------
- function As_Digit (C : Character) return Char_As_Digit
- is
+ function As_Digit (C : Character) return Char_As_Digit is
begin
case C is
when '0' .. '9' =>
@@ -133,7 +132,9 @@ package body System.Val_Real is
Trailing_Zeros : Natural := 0;
-- Number of trailing zeros at a given point.
+
begin
+ pragma Assert (Base in 2 .. 16);
-- If initial Scale is not 0 then it means that Precision_Limit was
-- reached during integral part scanning.
@@ -217,7 +218,6 @@ package body System.Val_Real is
end if;
end if;
end loop;
-
end Scan_Decimal_Digits;
--------------------------
@@ -268,6 +268,8 @@ package body System.Val_Real is
-- Precision limit has been reached so just update the exponent
Scale := Scale + 1;
else
+ pragma Assert (Base /= 0);
+
if Value > (Precision_Limit - Digit) / Base then
-- Updating Value will overflow so ignore this digit and any
-- following ones. Only update the scale
@@ -369,6 +371,10 @@ package body System.Val_Real is
-- First character can be either a decimal digit or a dot.
if Str (Index) in '0' .. '9' then
+ pragma Annotate
+ (CodePeer, Intentional,
+ "test always true", "defensive code below");
+
-- If this is a digit it can indicates either the float decimal
-- part or the base to use
Scan_Integral_Digits