Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hello,

cppcheck detected this on core/cui/source/dialogs/SpellDialog.cxx
1534    nullPointer     error   Possible null pointer dereference: pNewError
1538    nullPointer     error   Possible null pointer dereference: pNewError
1555    nullPointer     error   Possible null pointer dereference: pNewError
1559    nullPointer     error   Possible null pointer dereference: pNewError
1570    nullPointer     error   Possible null pointer dereference: pNewBack
1595    nullPointer     error   Possible null pointer dereference: pNewError
1751    nullPointer     error   Possible null pointer dereference: pNewBackground

I tried to understand with the first one :
 1530           TextAttrib* pNewError =  NULL;
                    sal_uInt16 nStart = pErrorAttrLeft->GetStart();
                    sal_uInt16 nEnd = pErrorAttrLeft->GetEnd();
                    pTextEngine->RemoveAttrib( 0, *pErrorAttrLeft );
  1534          SetAttrib( *pNewError, 0, nStart, ++nEnd );

Then i went there :
   1825 void SentenceEditWindow_Impl::SetAttrib( const TextAttrib& rAttr,
sal_uLong nPara, sal_uInt16 nStart, sal_uInt16 nEnd )
   1826 {
   1827     GetTextEngine()->SetAttrib(rAttr, nPara, nStart, nEnd);
   1828 }

Then here :
void TextEngine::SetAttrib( const TextAttrib& rAttr, sal_uLong nPara,
sal_uInt16 nStart, sal_uInt16 nEnd, sal_Bool bIdleFormatAndUpdate )
   2775 {
   2776     // Es wird hier erstmal nicht geprueft, ob sich Attribute
ueberlappen!
   2777     // Diese Methode ist erstmal nur fuer einen Editor, der fuer
eine Zeile
   2778     // _schnell_ das Syntax-Highlight einstellen will.
   2779 
   2780     // Da die TextEngine z.Zt fuer Editoren gedacht ist gibt es auch
kein
   2781     // Undo fuer Attribute!
   2782 
   2783     if ( nPara < mpDoc->GetNodes().Count() )
   2784     {
   2785         TextNode* pNode = mpDoc->GetNodes().GetObject( nPara );
   2786         TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject(
nPara );
   2787 
   2788         sal_uInt16 nMax = pNode->GetText().Len();
   2789         if ( nStart > nMax )
   2790             nStart = nMax;
   2791         if ( nEnd > nMax )
   2792             nEnd = nMax;
   2793 
   2794         pNode->GetCharAttribs().InsertAttrib( new TextCharAttrib(
rAttr, nStart, nEnd ) );

     56 TextCharAttrib::TextCharAttrib( const TextAttrib& rAttr, sal_uInt16
nStart, sal_uInt16 nEnd )
     57 {
     58     mpAttr = rAttr.Clone();
     59     mnStart = nStart,
     60     mnEnd = nEnd;
     61 }


I found that before the commit  d54c3ad1518e32938117c7e529dda375d4110888,
most (all?) of these variables were initialized. For example like this :
TextAttrib* pNewError =  pErrorAttrib->GetAttr().Clone();

I supposed there was certainly a good reason, but I don't know how can it
works now. Of course, I wouldn't have noticed this without cppcheck report.

Julien.



--
View this message in context: 
http://nabble.documentfoundation.org/Question-about-Possible-null-pointer-dereference-in-SpellDialog-cxx-cui-one-tp3343305p3343305.html
Sent from the Dev mailing list archive at Nabble.com.

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.