]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Cleanup use of local scalars in GNAT.Socket.Get_Address_Info
authorPiotr Trojanek <trojanek@adacore.com>
Tue, 14 Jun 2022 11:47:27 +0000 (13:47 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 6 Jul 2022 13:29:48 +0000 (13:29 +0000)
A cleanup opportunity spotted while working on improved detection of
uninitialised local scalar objects.

gcc/ada/

* libgnat/g-socket.adb (Get_Address_Info): Reduce scope of the
Found variable; avoid repeated assignment inside the loop.

gcc/ada/libgnat/g-socket.adb

index 4267d9f408fd18389f832de1ad59c9f29e9e9f99..86ce3b84372c3adc8245c307735f603030492eb0 100644 (file)
@@ -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;