From 6c1929894ca27ab2469c2c7bf25ad2625f567351 Mon Sep 17 00:00:00 2001 From: Arnaud Charlet Date: Thu, 3 Sep 2020 04:04:22 -0400 Subject: [PATCH] [Ada] Fix logic in C_Select under mingw 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. --- gcc/ada/libgnat/g-socthi__mingw.adb | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/gcc/ada/libgnat/g-socthi__mingw.adb b/gcc/ada/libgnat/g-socthi__mingw.adb index f63a6cb..dd8a68c 100644 --- 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; -- 2.7.4