[Libreoffice-commits] core.git: lingucomponent/source

Stephan Bergmann sbergman at redhat.com
Sat Feb 25 15:50:58 UTC 2017


 lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx |   27 +++++++++++++-----
 1 file changed, 20 insertions(+), 7 deletions(-)

New commits:
commit 4520435ad59802b6a567b3bb6c77927663be0f81
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Sat Feb 25 16:50:23 2017 +0100

    Clean up use of integer types
    
    Change-Id: I06364be5bbbe7862d20ea24ee155cf468f63f0b0

diff --git a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
index 4b13583..5bf39b1 100644
--- a/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
+++ b/lingucomponent/source/hyphenator/hyphen/hyphenimp.cxx
@@ -50,6 +50,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <cassert>
 #include <list>
 #include <set>
 #include <memory>
@@ -617,7 +618,7 @@ Reference< XPossibleHyphens > SAL_CALL Hyphenator::createPossibleHyphens( const
         // now convert word to needed encoding
         OString encWord(OU2ENC(nTerm,eEnc));
 
-        int wordlen = encWord.getLength();
+        sal_Int32 wordlen = encWord.getLength();
         std::unique_ptr<char[]> lcword(new char[wordlen+1]);
         std::unique_ptr<char[]> hyphens(new char[wordlen+5]);
         char ** rep = nullptr; // replacements of discretionary hyphenation
@@ -628,7 +629,7 @@ Reference< XPossibleHyphens > SAL_CALL Hyphenator::createPossibleHyphens( const
         strcpy(lcword.get(),encWord.getStr());
 
         // first remove any trailing periods
-        int n = wordlen-1;
+        sal_Int32 n = wordlen-1;
         while((n >=0) && (lcword[n] == '.'))
             n--;
         n++;
@@ -655,14 +656,13 @@ Reference< XPossibleHyphens > SAL_CALL Hyphenator::createPossibleHyphens( const
             }
         }
         // now backfill hyphens[] for any removed periods
-        for (int c = n; c < wordlen; c++)
+        for (sal_Int32 c = n; c < wordlen; c++)
             hyphens[c] = '0';
         hyphens[wordlen] = '\0';
 
-        sal_Int16 nHyphCount = 0;
-        sal_Int16 i;
+        sal_Int32 nHyphCount = 0;
 
-        for ( i = 0; i < encWord.getLength(); i++)
+        for ( sal_Int32 i = 0; i < encWord.getLength(); i++)
         {
             if (hyphens[i]&1)
                 nHyphCount++;
@@ -673,12 +673,25 @@ Reference< XPossibleHyphens > SAL_CALL Hyphenator::createPossibleHyphens( const
         OUStringBuffer hyphenatedWordBuffer;
         nHyphCount = 0;
 
-        for (i = 0; i < nWord.getLength(); i++)
+        for (sal_Int32 i = 0; i < nWord.getLength(); i++)
         {
             hyphenatedWordBuffer.append(aWord[i]);
             // hyphenation position
             if (hyphens[i]&1)
             {
+                // linguistic::PossibleHyphens is stuck with
+                // css::uno::Sequence<sal_Int16> because of
+                // css.linguistic2.XPossibleHpyhens.getHyphenationPositions, so
+                // any further positions need to be ignored:
+                assert(i >= SAL_MIN_INT16);
+                if (i > SAL_MAX_INT16)
+                {
+                    SAL_WARN(
+                        "lingucomponent",
+                        "hyphen pos " << i << " > SAL_MAX_INT16 in \"" << aWord
+                            << "\"");
+                    continue;
+                }
                 pPos[nHyphCount] = i;
                 hyphenatedWordBuffer.append('=');
                 nHyphCount++;


More information about the Libreoffice-commits mailing list