uxtheme Prevent segfault if no theme is set

Robert Shearman R.J.Shearman at warwick.ac.uk
Sun Jan 25 05:18:10 CST 2004

> This follows the same lines, in some cases
> MSSTYLES_SetActiveTheme would return success when in fact it failed
> Apply on top of Vitaliy's patch
> Changelog:
> 	Ensure MSSTYLES_SetActiveTheme fails when theme fails to load


>  invalid_theme:
>      if(hTheme) FreeLibrary(hTheme);
> -    if(!hr) hr = HRESULT_FROM_WIN32(GetLastError());
> +    if(SUCCEEDED(hr)) hr = HRESULT_FROM_WIN32(GetLastError());
> +    if(SUCCEEDED(hr)) hr = E_FAIL;
>      return hr;

You shouldn't be doing this in the first place. As you have seen, at best
you will set hr to a random error and at worst it won't be set at all and
you need your hack to make it still work.
What you should be doing is setting hr to the correct error as soon as you
detect a failure. So after a Win32 call:
if (callfailed)
    hr = HRESULT_FROM_WIN32(GetLastError());
    goto invalid_theme;

or after another type of failure:

if (somethingnotquiteright)
    hr = E_FAIL;
    goto invalid_theme;

Also, please try to use a more descriptive code than E_FAIL if one exists.


More information about the wine-devel mailing list