GNAT started generated a new legitimate warning on g-socthi__mingw.adb:
g-socthi.adb:395:19: warning: condition is always True
After further investigation, it appears that Original_WFS was
unconditionally dereferencing Writefds without first checking against null.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* libgnat/g-socthi__mingw.adb (C_Select): Fix logic in code and
make it explicit that we are checking against null values before
dereferencing them.
diff --git a/gcc/ada/libgnat/g-socthi__mingw.adb b/gcc/ada/libgnat/g-socthi__mingw.adb
--- a/gcc/ada/libgnat/g-socthi__mingw.adb
+++ b/gcc/ada/libgnat/g-socthi__mingw.adb
@@ -375,13 +375,10 @@ package body GNAT.Sockets.Thin is
Exceptfds : access Fd_Set;
Timeout : Timeval_Access) return C.int
is
- pragma Warnings (Off, Exceptfds);
-
- Original_WFS : aliased constant Fd_Set := Writefds.all;
-
- Res : C.int;
- S : aliased C.int;
- Last : aliased C.int;
+ Original_WFS : aliased Fd_Set;
+ Res : C.int;
+ S : aliased C.int;
+ Last : aliased C.int;
begin
-- Asynchronous connection failures are notified in the exception fd
@@ -392,7 +389,8 @@ package body GNAT.Sockets.Thin is
-- present in the initial write fd set, then move the socket from the
-- exception fd set to the write fd set.
- if Writefds /= No_Fd_Set_Access then
+ if Writefds /= null then
+ Original_WFS := Writefds.all;
-- Add any socket present in write fd set into exception fd set
@@ -411,7 +409,7 @@ package body GNAT.Sockets.Thin is
Res := Standard_Select (Nfds, Readfds, Writefds, Exceptfds, Timeout);
- if Exceptfds /= No_Fd_Set_Access then
+ if Exceptfds /= null then
declare
EFSC : aliased Fd_Set := Exceptfds.all;
Flag : constant C.int := SOSC.MSG_PEEK + SOSC.MSG_OOB;
@@ -448,8 +446,8 @@ package body GNAT.Sockets.Thin is
-- exception fd set back to write fd set. Otherwise, ignore
-- this event since the user is not watching for it.
- if Writefds /= No_Fd_Set_Access
- and then (Is_Socket_In_Set (Original_WFS'Access, S) /= 0)
+ if Writefds /= null
+ and then Is_Socket_In_Set (Original_WFS'Access, S) /= 0
then
Insert_Socket_In_Set (Writefds, S);
end if;
@@ -457,6 +455,7 @@ package body GNAT.Sockets.Thin is
end loop;
end;
end if;
+
return Res;
end C_Select;