[PATCH] avoid Possible null pointer dereference in linguistic/source/spelldsp.hxx

Ivan Timofeev timofeev.i.s at gmail.com
Sat Feb 11 07:54:49 PST 2012


Hi Julien,

On 11.02.2012 19:21, julien2412 wrote:
> Cppcheck reports this :
> [spelldsp.hxx:138]: (error) Possible null pointer dereference: pCache -
> otherwise it is redundant to check if pCache is null at line 136
>
> Here are the lines :
>      134 inline linguistic::SpellCache&  SpellCheckerDispatcher::GetCache()
> const
>      135 {
>      136     if (!pCache)
>      137         ((SpellCheckerDispatcher *) this)->pCache = new
> linguistic::SpellCache();
>      138     return *pCache;
>      139 }

This report is a false positive. If pCache is 0, it will be created. It 
seems cppcheck became confused by "(SpellCheckerDispatcher *) this" 
cast. IMHO pCache should be declared as mutable and then the cast may be 
removed.

Regards,
Ivan


More information about the LibreOffice mailing list