On Wednesday 27 November 2024 18:33:37 Pali Rohár wrote:
> Use _initterm_e() for executing functions in __xi_a[] ... __xi_z[] array.
> This function properly stops execution on error and returns error value.
> Same logic is doing Visual C++ startup code.
> 
> This fixes error handling of function callbacks defined in that array.

Also the casting from function pointer which returns int to function
pointer which returns void sounds like a bug in code.

I guess that currently it is working only because the return value on
x86 is passed via register and it can be ignored by the caller.

> ---
>  mingw-w64-crt/crt/crtdll.c | 3 ++-
>  mingw-w64-crt/crt/crtexe.c | 3 ++-
>  2 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/mingw-w64-crt/crt/crtdll.c b/mingw-w64-crt/crt/crtdll.c
> index 754648a6382b..7894466c6f85 100644
> --- a/mingw-w64-crt/crt/crtdll.c
> +++ b/mingw-w64-crt/crt/crtdll.c
> @@ -97,7 +97,8 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD 
> dwReason, LPVOID lpreserved)
>       {
>         __native_startup_state = __initializing;
>         
> -       _initterm ((_PVFV *) (void *) __xi_a, (_PVFV *) (void *) __xi_z);
> +       if (_initterm_e (__xi_a, __xi_z) != 0)
> +         return FALSE;
>       }
>        if (__native_startup_state == __initializing)
>       {
> diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c
> index 4f058a8e1f5f..a21a0ebe5526 100644
> --- a/mingw-w64-crt/crt/crtexe.c
> +++ b/mingw-w64-crt/crt/crtexe.c
> @@ -229,7 +229,8 @@ __tmainCRTStartup (void)
>      else if (__native_startup_state == __uninitialized)
>        {
>       __native_startup_state = __initializing;
> -     _initterm ((_PVFV *)(void *)__xi_a, (_PVFV *)(void *) __xi_z);
> +     if (_initterm_e (__xi_a, __xi_z) != 0)
> +       return 255;
>        }
>      else
>        has_cctor = 1;
> -- 
> 2.20.1
> 


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

Reply via email to