[Libreoffice-commits] core.git: basegfx/source basic/source include/rtl sc/source svl/source sw/source tools/source vcl/source xmloff/source

Noel Grandin noel at peralex.com
Wed Oct 23 04:14:16 PDT 2013


 basegfx/source/polygon/b2dsvgpolypolygon.cxx |   12 ++++++---
 basic/source/comp/scanner.cxx                |   17 +++++++------
 basic/source/comp/token.cxx                  |    5 ++-
 include/rtl/ustring.hxx                      |    6 ----
 sc/source/core/data/table3.cxx               |    6 ++--
 sc/source/filter/xml/xmlimprt.cxx            |    2 -
 svl/source/misc/urihelper.cxx                |    4 +--
 sw/source/core/crsr/bookmrk.cxx              |    4 +--
 sw/source/core/edit/edattr.cxx               |    2 -
 sw/source/core/text/itrform2.cxx             |    2 -
 sw/source/core/text/pormulti.cxx             |    2 -
 sw/source/core/text/txtfrm.cxx               |    2 -
 sw/source/filter/ww8/writerwordglue.cxx      |    2 -
 tools/source/stream/stream.cxx               |   12 ++++-----
 vcl/source/gdi/outdev3.cxx                   |    2 -
 vcl/source/window/mnemonic.cxx               |    6 ++--
 xmloff/source/draw/xexptran.cxx              |   34 +++++++++++++++++++--------
 xmloff/source/style/fonthdl.cxx              |    2 -
 18 files changed, 70 insertions(+), 52 deletions(-)

New commits:
commit 8396cce9b5d9a4e3cdccc558eb1b818460f0987a
Author: Noel Grandin <noel at peralex.com>
Date:   Mon Oct 21 09:53:57 2013 +0200

    clean up places accessing the NULL at the of an OUString
    
    There were only a couple of real bugs fixed, but we're a little
    bit safer now.
    This also fixes the assert and the comment in OUString::operator[]
    about this.
    
    Change-Id: Ibe16b5794e0ba7ecd345fa0801586d25b015974c

diff --git a/basegfx/source/polygon/b2dsvgpolypolygon.cxx b/basegfx/source/polygon/b2dsvgpolypolygon.cxx
index ffb0491..d9b869b 100644
--- a/basegfx/source/polygon/b2dsvgpolypolygon.cxx
+++ b/basegfx/source/polygon/b2dsvgpolypolygon.cxx
@@ -88,24 +88,28 @@ namespace basegfx
                 {
                     if (sal_Unicode('.') == aChar) separator_seen = true;
                     sNumberString.append(rStr[io_rPos]);
-                    aChar = rStr[++io_rPos];
+                    io_rPos++;
+                    aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0;
                 }
 
                 if(sal_Unicode('e') == aChar || sal_Unicode('E') == aChar)
                 {
                     sNumberString.append(rStr[io_rPos]);
-                    aChar = rStr[++io_rPos];
+                    io_rPos++;
+                    aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0;
 
                     if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar)
                     {
                         sNumberString.append(rStr[io_rPos]);
-                        aChar = rStr[++io_rPos];
+                        io_rPos++;
+                        aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0;
                     }
 
                     while(sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar)
                     {
                         sNumberString.append(rStr[io_rPos]);
-                        aChar = rStr[++io_rPos];
+                        io_rPos++;
+                        aChar = io_rPos < rStr.getLength() ? rStr[io_rPos] : 0;
                     }
                 }
 
diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index 0a5a493..3609765 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -401,13 +401,16 @@ bool SbiScanner::NextSym()
             GenError( SbERR_MATH_OVERFLOW );
 
         // type recognition?
-        SbxDataType t(GetSuffixType(aLine[nCol]));
-        if( t != SbxVARIANT )
+        if( nCol < aLine.getLength() )
         {
-            eScanType = t;
-            ++pLine;
-            ++nCol;
-        }
+            SbxDataType t(GetSuffixType(aLine[nCol]));
+            if( t != SbxVARIANT )
+            {
+                eScanType = t;
+                ++pLine;
+                ++nCol;
+            }
+       }
     }
 
     // Hex/octal number? Read in and convert:
@@ -531,7 +534,7 @@ bool SbiScanner::NextSym()
 PrevLineCommentLbl:
 
     if( bPrevLineExtentsComment || (eScanType != SbxSTRING &&
-                                    ( aSym[0] == '\'' || aSym.equalsIgnoreAsciiCase( "REM" ) ) ) )
+                                    ( aSym.startsWith("'") || aSym.equalsIgnoreAsciiCase( "REM" ) ) ) )
     {
         bPrevLineExtentsComment = false;
         aSym = OUString("REM");
diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx
index beff37d..bf5231a 100644
--- a/basic/source/comp/token.cxx
+++ b/basic/source/comp/token.cxx
@@ -344,9 +344,10 @@ SbiToken SbiTokenizer::Next()
         return eCurTok = EOLN;
     }
 
-    if( aSym[0] == '\n' )
+    if( aSym.startsWith("\n") )
     {
-        bEos = true; return eCurTok = EOLN;
+        bEos = true;
+        return eCurTok = EOLN;
     }
     bEos = false;
 
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index ba8c358..45a7441 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -417,11 +417,7 @@ public:
       @since LibreOffice 3.5
     */
     sal_Unicode operator [](sal_Int32 index) const {
-        assert(index >= 0 && index <= getLength());
-            //TODO: should really check for < getLength(), but there is quite
-            // some clever code out there that violates this function's
-            // documented precondition and relies on s[s.getLength()] == 0 and
-            // that would need to be fixed first
+        assert(index >= 0 && index < getLength());
         return getStr()[index];
     }
 
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 61aa637..73a514b 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -2161,7 +2161,7 @@ bool ScTable::CreateStarQuery(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2
         {
             bFound = false;
             GetUpperCellString(nCol1 + 2, nRow, aCellStr);
-            if (aCellStr[0] == '<')
+            if (aCellStr.startsWith("<"))
             {
                 if (aCellStr[1] == '>')
                     rEntry.eOp = SC_NOT_EQUAL;
@@ -2170,14 +2170,14 @@ bool ScTable::CreateStarQuery(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2
                 else
                     rEntry.eOp = SC_LESS;
             }
-            else if (aCellStr[0] == '>')
+            else if (aCellStr.startsWith(">"))
             {
                 if (aCellStr[1] == '=')
                     rEntry.eOp = SC_GREATER_EQUAL;
                 else
                     rEntry.eOp = SC_GREATER;
             }
-            else if (aCellStr[0] == '=')
+            else if (aCellStr.startsWith("="))
                 rEntry.eOp = SC_EQUAL;
 
         }
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index ac85870..cd8a47b 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -3022,7 +3022,7 @@ sal_Int32 ScXMLImport::GetRangeType(const OUString sRangeType) const
     sal_Int16 i = 0;
     while (i <= sRangeType.getLength())
     {
-        if ((sRangeType[i] == ' ') || (i == sRangeType.getLength()))
+        if ((i == sRangeType.getLength()) || (sRangeType[i] == ' '))
         {
             OUString sTemp = sBuffer.makeStringAndClear();
             if (sTemp.compareToAscii(SC_REPEAT_COLUMN) == 0)
diff --git a/svl/source/misc/urihelper.cxx b/svl/source/misc/urihelper.cxx
index 32df0b6..f147f1a 100644
--- a/svl/source/misc/urihelper.cxx
+++ b/svl/source/misc/urihelper.cxx
@@ -527,7 +527,7 @@ OUString URIHelper::FindFirstURLInText(OUString const & rText,
                     while (i != rEnd
                            && checkWChar(rCharClass, rText, &i, &nUriEnd, true,
                                          true)) ;
-                    if (i != nPrefixEnd && rText[i] == (sal_Unicode)'#')
+                    if (i != nPrefixEnd && i != rEnd && rText[i] == '#')
                     {
                         ++i;
                         while (i != rEnd
@@ -555,7 +555,7 @@ OUString URIHelper::FindFirstURLInText(OUString const & rText,
                     sal_Int32 nUriEnd = i;
                     while (i != rEnd
                            && checkWChar(rCharClass, rText, &i, &nUriEnd)) ;
-                    if (i != nPrefixEnd && rText[i] == '#')
+                    if (i != nPrefixEnd && i != rEnd && rText[i] == '#')
                     {
                         ++i;
                         while (i != rEnd
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index 3a4ba43..962f526 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -70,11 +70,11 @@ namespace
         SwTxtNode const*const pStartTxtNode =
             rStart.nNode.GetNode().GetTxtNode();
         SwTxtNode const*const pEndTxtNode = rEnd.nNode.GetNode().GetTxtNode();
-        const sal_Unicode ch_start =
+        const sal_Unicode ch_start = ( rStart.nContent.GetIndex() >= pStartTxtNode->GetTxt().getLength() ) ? 0 :
             pStartTxtNode->GetTxt()[rStart.nContent.GetIndex()];
         xub_StrLen nEndPos = ( rEnd == rStart ||  rEnd.nContent.GetIndex() == 0 ) ?
             rEnd.nContent.GetIndex() : rEnd.nContent.GetIndex() - 1;
-        const sal_Unicode ch_end = pEndTxtNode->GetTxt()[nEndPos];
+        const sal_Unicode ch_end = nEndPos >= pEndTxtNode->GetTxt().getLength() ? 0 : pEndTxtNode->GetTxt()[nEndPos];
         SwPaM aStartPaM(rStart);
         SwPaM aEndPaM(rEnd);
 
diff --git a/sw/source/core/edit/edattr.cxx b/sw/source/core/edit/edattr.cxx
index d9cfcad..8e01455 100644
--- a/sw/source/core/edit/edattr.cxx
+++ b/sw/source/core/edit/edattr.cxx
@@ -493,7 +493,7 @@ static bool lcl_IsNoEndTxtAttrAtPos( const SwTxtNode& rTNd, xub_StrLen nPos,
     }
 
     // and fields
-    if (CH_TXTATR_BREAKWORD == rTNd.GetTxt()[nPos])
+    if (nPos < rTNd.GetTxt().getLength() && CH_TXTATR_BREAKWORD == rTNd.GetTxt()[nPos])
     {
         const SwTxtAttr* const pAttr = rTNd.GetTxtAttrForCharAt( nPos );
         if (pAttr)
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 180b240..5c28461 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -2027,7 +2027,7 @@ sal_Bool SwTxtFormatter::AllowRepaintOpt() const
     const xub_StrLen nReformat = GetInfo().GetReformatStart();
     if( bOptimizeRepaint && STRING_LEN != nReformat )
     {
-        const sal_Unicode cCh = GetInfo().GetTxt()[ nReformat ];
+        const sal_Unicode cCh = nReformat >= GetInfo().GetTxt().getLength() ? 0 : GetInfo().GetTxt()[ nReformat ];
         bOptimizeRepaint = ( CH_TXTATR_BREAKWORD != cCh && CH_TXTATR_INWORD != cCh )
                             || ! GetInfo().HasHint( nReformat );
     }
diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx
index ab18a82..9c1c057 100644
--- a/sw/source/core/text/pormulti.cxx
+++ b/sw/source/core/text/pormulti.cxx
@@ -885,7 +885,7 @@ SwMultiCreator* SwTxtSizeInfo::GetMultiCreator( xub_StrLen &rPos,
     sal_uInt8 nNextLevel = nCurrLevel;
     bool bFldBidi = false;
 
-    if ( CH_TXTATR_BREAKWORD == GetChar( rPos ) )
+    if ( rPos < GetTxt().getLength() && CH_TXTATR_BREAKWORD == GetChar( rPos ) )
     {
         bFldBidi = true;
     }
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index 03dbba3..acb60ef 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -648,7 +648,7 @@ xub_StrLen SwTxtFrm::FindBrk( const OUString &rTxt,
                               const sal_Int32 nEnd ) const
 {
     sal_Int32 nFound = nStart;
-    const sal_Int32 nEndLine = std::min( nEnd, rTxt.getLength() );
+    const sal_Int32 nEndLine = std::min( nEnd, rTxt.getLength() - 1 );
 
     // Wir ueberlesen erst alle Blanks am Anfang der Zeile (vgl. Bug 2235).
     while( nFound <= nEndLine && ' ' == rTxt[nFound] )
diff --git a/sw/source/filter/ww8/writerwordglue.cxx b/sw/source/filter/ww8/writerwordglue.cxx
index 35be5fa..af8c32e 100644
--- a/sw/source/filter/ww8/writerwordglue.cxx
+++ b/sw/source/filter/ww8/writerwordglue.cxx
@@ -827,9 +827,9 @@ namespace sw
                         if (!(IsPreviousAM(rParams, nI) && IsNextPM(rParams, nI)))
                         {
                             rParams = rParams.replaceAt(nI, 1, "\\/");
+                            nLen++;
                         }
                         nI++;
-                        nLen++;
                     }
 
                     // Deal with language differences in date format expression.
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index b688de1..32babd9 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -2045,16 +2045,16 @@ namespace
                 {
                     // Muessen wir Konvertieren
                     if ( ((eLineEnd != LINEEND_LF) && (rIn[i] == '\n')) ||
-                         ((eLineEnd == LINEEND_CRLF) && (rIn[i+1] != '\n')) ||
+                         ((eLineEnd == LINEEND_CRLF) && (i+1) < nStrLen && (rIn[i+1] != '\n')) ||
                          ((eLineEnd == LINEEND_LF) &&
-                          ((rIn[i] == '\r') || (rIn[i+1] == '\r'))) ||
+                          ((rIn[i] == '\r') || ((i+1) < nStrLen && rIn[i+1] == '\r'))) ||
                          ((eLineEnd == LINEEND_CR) &&
-                          ((rIn[i] == '\n') || (rIn[i+1] == '\n'))) )
+                          ((rIn[i] == '\n') || ((i+1) < nStrLen && rIn[i+1] == '\n'))) )
                         bConvert = true;
                 }
 
-                // skip char if \r\n oder \n\r
-                if ( ((rIn[i+1] == '\r') || (rIn[i+1] == '\n')) &&
+                // skip char if \r\n or \n\r
+                if ( (i+1) < nStrLen && ((rIn[i+1] == '\r') || (rIn[i+1] == '\n')) &&
                      (rIn[i] != rIn[i+1]) )
                     ++i;
             }
@@ -2087,7 +2087,7 @@ namespace
                         aNewData.append('\n');
                 }
 
-                if ( ((rIn[i+1] == '\r') || (rIn[i+1] == '\n')) &&
+                if ( (i+1) < nStrLen && ((rIn[i+1] == '\r') || (rIn[i+1] == '\n')) &&
                      (rIn[i] != rIn[i+1]) )
                     ++i;
             }
diff --git a/vcl/source/gdi/outdev3.cxx b/vcl/source/gdi/outdev3.cxx
index a9de972..d8ec0e6 100644
--- a/vcl/source/gdi/outdev3.cxx
+++ b/vcl/source/gdi/outdev3.cxx
@@ -4843,7 +4843,7 @@ long OutputDevice::ImplGetTextLines( ImplMultiTextLineInfo& rLineInfo,
                 nBreakPos++;
             nPos = nBreakPos;
 
-            if ( ( rStr[ nPos ] == '\r' ) || ( rStr[ nPos ] == '\n' ) )
+            if ( nPos < nLen && ( ( rStr[ nPos ] == '\r' ) || ( rStr[ nPos ] == '\n' ) ) )
             {
                 nPos++;
                 // CR/LF?
diff --git a/vcl/source/window/mnemonic.cxx b/vcl/source/window/mnemonic.cxx
index 0b55245..fe45ae8 100644
--- a/vcl/source/window/mnemonic.cxx
+++ b/vcl/source/window/mnemonic.cxx
@@ -208,14 +208,14 @@ OUString MnemonicGenerator::CreateMnemonic( const OUString& _rKey )
             }
 
             // Search for next word
-            do
+            nIndex++;
+            while ( nIndex < nLen )
             {
-                nIndex++;
                 c = aKey[ nIndex ];
                 if ( c == ' ' )
                     break;
+                nIndex++;
             }
-            while ( nIndex < nLen );
             nIndex++;
         }
         while ( nIndex < nLen );
diff --git a/xmloff/source/draw/xexptran.cxx b/xmloff/source/draw/xexptran.cxx
index f97aaac..5f13125 100644
--- a/xmloff/source/draw/xexptran.cxx
+++ b/xmloff/source/draw/xexptran.cxx
@@ -151,24 +151,33 @@ void Imp_SkipDouble(const OUString& rStr, sal_Int32& rPos, const sal_Int32)
     sal_Unicode aChar(rStr[rPos]);
 
     if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar)
-        aChar = rStr[++rPos];
+    {
+        ++rPos;
+        aChar = rPos >= rStr.getLength() ? 0 : rStr[rPos];
+    }
 
     while((sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar)
         || sal_Unicode('.') == aChar)
     {
-        aChar = rStr[++rPos];
+        ++rPos;
+        aChar = rPos >= rStr.getLength() ? 0 : rStr[rPos];
     }
 
     if(sal_Unicode('e') == aChar || sal_Unicode('E') == aChar)
     {
-        aChar = rStr[++rPos];
+        ++rPos;
+        aChar = rPos >= rStr.getLength() ? 0 : rStr[rPos];
 
         if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar)
-            aChar = rStr[++rPos];
+        {
+            ++rPos;
+            aChar = rPos >= rStr.getLength() ? 0 : rStr[rPos];
+        }
 
         while(sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar)
         {
-            aChar = rStr[++rPos];
+            ++rPos;
+            aChar = rPos >= rStr.getLength() ? 0 : rStr[rPos];
         }
     }
 }
@@ -182,31 +191,36 @@ double Imp_GetDoubleChar(const OUString& rStr, sal_Int32& rPos, const sal_Int32
     if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar)
     {
         sNumberString.append(rStr[rPos]);
-        aChar = rStr[++rPos];
+        ++rPos;
+        aChar = rPos >= nLen ? 0 : rStr[rPos];
     }
 
     while((sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar)
         || sal_Unicode('.') == aChar)
     {
         sNumberString.append(rStr[rPos]);
-        aChar = rStr[++rPos];
+        ++rPos;
+        aChar = rPos >= nLen ? 0 : rStr[rPos];
     }
 
     if(sal_Unicode('e') == aChar || sal_Unicode('E') == aChar)
     {
         sNumberString.append(rStr[rPos]);
-        aChar = rStr[++rPos];
+        ++rPos;
+        aChar = rPos >= nLen ? 0 : rStr[rPos];
 
         if(sal_Unicode('+') == aChar || sal_Unicode('-') == aChar)
         {
             sNumberString.append(rStr[rPos]);
-            aChar = rStr[++rPos];
+            ++rPos;
+            aChar = rPos >= nLen ? 0 : rStr[rPos];
         }
 
         while(sal_Unicode('0') <= aChar && sal_Unicode('9') >= aChar)
         {
             sNumberString.append(rStr[rPos]);
-            aChar = rStr[++rPos];
+            ++rPos;
+            aChar = rPos >= nLen ? 0 : rStr[rPos];
         }
     }
 
diff --git a/xmloff/source/style/fonthdl.cxx b/xmloff/source/style/fonthdl.cxx
index a2768e5..b61803a 100644
--- a/xmloff/source/style/fonthdl.cxx
+++ b/xmloff/source/style/fonthdl.cxx
@@ -81,7 +81,7 @@ bool XMLFontFamilyNamePropHdl::importXML( const OUString& rStrImpValue, uno::Any
             nFirst++;
 
         // remove quotes
-        sal_Unicode c = rStrImpValue[nFirst];
+        sal_Unicode c = nFirst > nLast ? 0 : rStrImpValue[nFirst];
         if( nFirst < nLast && (sal_Unicode('\'') == c || sal_Unicode('\"') == c) && rStrImpValue[nLast] == c )
         {
             nFirst++;


More information about the Libreoffice-commits mailing list