bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 6/6] Fix GCC compile warning for "bad-function-cast"


From: Torbjörn SVENSSON
Subject: [PATCH 6/6] Fix GCC compile warning for "bad-function-cast"
Date: Fri, 9 Jun 2023 21:00:32 +0200

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
---
 src/function.c             |  2 +-
 src/os.h                   |  5 +++++
 src/w32/compat/posixfcn.c  |  3 ++-
 src/w32/subproc/sub_proc.c |  4 ++--
 src/w32/w32os.c            | 20 +++++++++++++++-----
 5 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/src/function.c b/src/function.c
index d4636d73..b3718f5e 100644
--- a/src/function.c
+++ b/src/function.c
@@ -1673,7 +1673,7 @@ windows32_openpipe (int *pipedes, int errfd, pid_t 
*pid_p, char **command_argv,
           return -1;
         }
     }
-  tmpErr = (HANDLE)_get_osfhandle (errfd);
+  tmpErr = get_handle_for_fd (errfd);
   if (DuplicateHandle (GetCurrentProcess (), tmpErr,
                        GetCurrentProcess (), &hErr,
                        0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE)
diff --git a/src/os.h b/src/os.h
index cce9d34a..b6970204 100644
--- a/src/os.h
+++ b/src/os.h
@@ -156,3 +156,8 @@ void osync_release (void);
 #else
 int get_bad_stdin (void);
 #endif
+
+#if MK_OS_W32
+#include <ntdef.h> /* Needed for HANDLE */
+HANDLE get_handle_for_fd (int);
+#endif
diff --git a/src/w32/compat/posixfcn.c b/src/w32/compat/posixfcn.c
index 72fe5f2e..7ad0fe0b 100644
--- a/src/w32/compat/posixfcn.c
+++ b/src/w32/compat/posixfcn.c
@@ -22,6 +22,7 @@ this program.  If not, see <https://www.gnu.org/licenses/>.  
*/
 #include <stdarg.h>
 #include <errno.h>
 #include <windows.h>
+#include "os.h"
 
 #include "dlfcn.h"
 
@@ -125,7 +126,7 @@ dlclose (void *handle)
 int
 isatty (int fd)
 {
-  HANDLE fh = (HANDLE) _get_osfhandle (fd);
+  HANDLE fh = get_handle_for_fd (fd);
   DWORD con_mode;
 
   if (fh == INVALID_HANDLE_VALUE)
diff --git a/src/w32/subproc/sub_proc.c b/src/w32/subproc/sub_proc.c
index 8cfa533c..f5d7fe03 100644
--- a/src/w32/subproc/sub_proc.c
+++ b/src/w32/subproc/sub_proc.c
@@ -1481,7 +1481,7 @@ process_easy(
     }
   }
   if (outfd >= 0)
-    tmpOut = (HANDLE)_get_osfhandle (outfd);
+    tmpOut = get_handle_for_fd (outfd);
   else
     tmpOut = GetStdHandle (STD_OUTPUT_HANDLE);
   if (DuplicateHandle(GetCurrentProcess(),
@@ -1511,7 +1511,7 @@ process_easy(
     }
   }
   if (errfd >= 0)
-    tmpErr = (HANDLE)_get_osfhandle (errfd);
+    tmpErr = get_handle_for_fd (errfd);
   else
     tmpErr = GetStdHandle(STD_ERROR_HANDLE);
   if (DuplicateHandle(GetCurrentProcess(),
diff --git a/src/w32/w32os.c b/src/w32/w32os.c
index 9d6d1841..593af62f 100644
--- a/src/w32/w32os.c
+++ b/src/w32/w32os.c
@@ -43,10 +43,10 @@ check_io_state ()
 
   /* Could have used GetHandleInformation, but that isn't supported
      on Windows 9X.  */
-  outfd = (HANDLE)_get_osfhandle (fileno (stdout));
-  errfd = (HANDLE)_get_osfhandle (fileno (stderr));
+  outfd = get_handle_for_fd (fileno (stdout));
+  errfd = get_handle_for_fd (fileno (stderr));
 
-  if ((HANDLE)_get_osfhandle (fileno (stdin)) != INVALID_HANDLE_VALUE)
+  if (get_handle_for_fd (fileno (stdin)) != INVALID_HANDLE_VALUE)
     state |= IO_STDIN_OK;
   if (outfd != INVALID_HANDLE_VALUE)
     state |= IO_STDOUT_OK;
@@ -497,7 +497,7 @@ osync_release ()
 void
 fd_inherit(int fd)
 {
-  HANDLE fh = (HANDLE)_get_osfhandle(fd);
+  HANDLE fh = get_handle_for_fd(fd);
 
   if (fh && fh != INVALID_HANDLE_VALUE)
         SetHandleInformation(fh, HANDLE_FLAG_INHERIT, 1);
@@ -506,7 +506,7 @@ fd_inherit(int fd)
 void
 fd_noinherit(int fd)
 {
-  HANDLE fh = (HANDLE)_get_osfhandle(fd);
+  HANDLE fh = get_handle_for_fd(fd);
 
   if (fh && fh != INVALID_HANDLE_VALUE)
         SetHandleInformation(fh, HANDLE_FLAG_INHERIT, 0);
@@ -515,3 +515,13 @@ fd_noinherit(int fd)
 void
 fd_set_append (int fd UNUSED)
 {}
+
+
+HANDLE
+get_handle_for_fd (int fd)
+{
+  /* This funcion call is needed to get around the "bad-function-cast"-warning
+     emitted by GCC when casting and assigning in the same statement.  */
+  intptr_t fh = _get_osfhandle(fd);
+  return (HANDLE) fh;
+}
-- 
2.25.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]