* [Ada] Cleanup use of local scalars in GNAT.Socket.Get_Address_Info
@ 2022-07-06 13:31 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-07-06 13:31 UTC (permalink / raw)
To: gcc-patches; +Cc: Piotr Trojanek
[-- Attachment #1: Type: text/plain, Size: 290 bytes --]
A cleanup opportunity spotted while working on improved detection of
uninitialised local scalar objects.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* libgnat/g-socket.adb (Get_Address_Info): Reduce scope of the
Found variable; avoid repeated assignment inside the loop.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1334 bytes --]
diff --git a/gcc/ada/libgnat/g-socket.adb b/gcc/ada/libgnat/g-socket.adb
--- a/gcc/ada/libgnat/g-socket.adb
+++ b/gcc/ada/libgnat/g-socket.adb
@@ -1036,7 +1036,6 @@ package body GNAT.Sockets is
R : C.int;
Iter : Addrinfo_Access;
- Found : Boolean;
function To_Array return Address_Info_Array;
-- Convert taken from OS addrinfo list A into Address_Info_Array
@@ -1046,8 +1045,6 @@ package body GNAT.Sockets is
--------------
function To_Array return Address_Info_Array is
- Result : Address_Info_Array (1 .. 8);
-
procedure Unsupported;
-- Calls Unknown callback if defiend
@@ -1066,6 +1063,9 @@ package body GNAT.Sockets is
end if;
end Unsupported;
+ Found : Boolean;
+ Result : Address_Info_Array (1 .. 8);
+
-- Start of processing for To_Array
begin
@@ -1087,8 +1087,8 @@ package body GNAT.Sockets is
if Result (J).Addr.Family = Family_Unspec then
Unsupported;
else
+ Found := False;
for M in Modes'Range loop
- Found := False;
if Modes (M) = Iter.ai_socktype then
Result (J).Mode := M;
Found := True;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-07-06 13:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-06 13:31 [Ada] Cleanup use of local scalars in GNAT.Socket.Get_Address_Info Pierre-Marie de Rodat
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).