[Libreoffice] Help fixing ImplHandleInputLangChange implementation
Jesús Corrius
jesus at softcatala.org
Mon Jun 20 11:47:47 PDT 2011
Hi all,
I'd like to fix this function implementation, as it makes my eyes cry ;)
Notice that if pFrame == NULL, the function will crash anyway because
it's only checked in the first if block and later is dereferenced.
static void ImplHandleInputLangChange( HWND hWnd, WPARAM, LPARAM lParam )
{
ImplSalYieldMutexAcquireWithWait();
// Feststellen, ob wir IME unterstuetzen
WinSalFrame* pFrame = GetWindowPtr( hWnd );
if ( pFrame && pFrame->mbIME && pFrame->mhDefIMEContext )
{
HKL hKL = (HKL)lParam;
UINT nImeProps = ImmGetProperty( hKL, IGP_PROPERTY );
pFrame->mbSpezIME = (nImeProps & IME_PROP_SPECIAL_UI) != 0;
pFrame->mbAtCursorIME = (nImeProps & IME_PROP_AT_CARET) != 0;
pFrame->mbHandleIME = !pFrame->mbSpezIME;
}
// trigger input language and codepage update
UINT nLang = pFrame->mnInputLang;
ImplUpdateInputLang( pFrame );
// notify change
if( nLang != pFrame->mnInputLang )
pFrame->CallCallback( SALEVENT_INPUTLANGUAGECHANGE, 0 );
ImplSalYieldMutexRelease();
}
What's the preferred way to fix it?
a) put everything in an if (pFrame) {....} block
b) if(!pFrame) return;
Thanks for the help! :)
--
Jesús Corrius <jesus at softcatala.org>
Document Foundation founding member
Mobile: +34 661 11 38 26
Skype: jcorrius | Twitter: @jcorrius
More information about the LibreOffice
mailing list