On Wednesday 31 July 2024 00:13:24 LIU Hao wrote:
> 在 2024-07-29 02:58, Pali Rohár 写道:
> > profile/profil.c: In function ‘profile_on’:
> > profile/profil.c:140:36: warning: cast between incompatible function types 
> > from ‘void (__attribute__((stdcall)) *)(void *)’ to ‘DWORD 
> > (__attribute__((stdcall)) *)(void *)’ [-Wcast-function-type]
> >     p->profthr = CreateThread (0, 0, (DWORD (WINAPI *)(LPVOID)) 
> > profthr_func,
> 
> This function should not return void.
> 

I see... It is even explicitly mentioned on MSDN:
https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms686736(v=vs.85)

"Do not declare this callback function with a void return type and cast
the function pointer to LPTHREAD_START_ROUTINE when creating the thread.
Code that does this is common, but it can crash on 64-bit Windows."

What about this change? I'm really not sure what this profthr_func()
should return. It looks like that its return value is ignored at all.

diff --git a/mingw-w64-crt/profile/profil.c b/mingw-w64-crt/profile/profil.c
index 6fed2e920432..e747b28b1150 100644
--- a/mingw-w64-crt/profile/profil.c
+++ b/mingw-w64-crt/profile/profil.c
@@ -70,9 +70,9 @@ print_prof (struct profinfo *p)
 /* Everytime we wake up use the main thread pc to hash into the cell in the
    profile buffer ARG. */
 
-static void CALLBACK profthr_func (LPVOID);
+static DWORD CALLBACK profthr_func (LPVOID);
 
-static void CALLBACK
+static DWORD CALLBACK
 profthr_func (LPVOID arg)
 {
   struct profinfo *p = (struct profinfo *) arg;
@@ -91,7 +91,7 @@ profthr_func (LPVOID arg)
 #endif
       /* Check quit condition, WAIT_OBJECT_0 or WAIT_TIMEOUT */
       if (WaitForSingleObject (p->quitevt, SLEEPTIME) == WAIT_OBJECT_0)
-       return;
+       return 0;
     }
 }
 


_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to