[PATCH v3 2/4] kernelbase: Preserve last error when GetEnvironmentVariableA succeeds.

Alexandre Julliard julliard at winehq.org
Thu Jan 23 15:46:31 CST 2020


Vladimir Panteleev <git at vladimir.panteleev.md> writes:

> @@ -1234,7 +1234,9 @@ DWORD WINAPI DECLSPEC_HOTPATCH GetEnvironmentVariableA( LPCSTR name, LPSTR value
>  {
>      UNICODE_STRING us_name;
>      PWSTR valueW;
> -    DWORD ret;
> +    DWORD ret, last_err;
> +
> +    last_err = GetLastError();
>  
>      /* limit the size to sane values */
>      size = min( size, 32767 );
> @@ -1249,7 +1251,11 @@ DWORD WINAPI DECLSPEC_HOTPATCH GetEnvironmentVariableA( LPCSTR name, LPSTR value
>       * - an error (GetLastError() != 0)
>       * - returning an empty string (in this case, we need to update the buffer)
>       */
> -    if (ret == 0 && size && GetLastError() == 0) value[0] = 0;
> +    if (GetLastError() == 0)
> +    {
> +        SetLastError(last_err);
> +        if (ret == 0 && size) value[0] = 0;
> +    }

It would be cleaner to avoid changing last error at all, instead of
saving and restoring it.

-- 
Alexandre Julliard
julliard at winehq.org



More information about the wine-devel mailing list