Jinoh Kang (@iamahuman) commented about dlls/windows.media.speech/recognizer.c:
- HRESULT hr = S_OK;
- TRACE("iface %p, action %p.\n", iface, action);
- *action = NULL;
- EnterCriticalSection(&impl->cs);
- if (!impl->worker_running && !impl->worker_thread && SUCCEEDED(hr = async_action_create(NULL, session_start_async, action)))
- {
impl->worker_running = TRUE;
if (!(impl->worker_thread = CreateThread(NULL, 0, session_worker_thread_cb, impl, 0, NULL)))
{
hr = HRESULT_FROM_WIN32(GetLastError());
impl->worker_running = FALSE;
}
impl->recognizer_state = SpeechRecognizerState_Capturing;
This changes the `recognizer_state` regardless of whether the thread creation succeeds or not.
```suggestion:-6+0 if ((impl->worker_thread = CreateThread(NULL, 0, session_worker_thread_cb, impl, 0, NULL))) { impl->worker_running = TRUE; impl->recognizer_state = SpeechRecognizerState_Capturing; } else { hr = HRESULT_FROM_WIN32(GetLastError()); } ```
However, in general this function should be improved in a direction that reduces nested `if`s. You can also replace `invalid_state = TRUE` with `hr = COR_E_INVALIDOPERATION`. Nested `if`s can be replaced by successive `if (SUCCEEDED(hr) [&& ...] )` statements.