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

Noel Grandin noel.grandin at collabora.co.uk
Mon Jun 19 08:50:42 UTC 2017


 writerfilter/source/rtftok/rtfdocumentimpl.cxx |  101 ++++++++++++-------------
 1 file changed, 52 insertions(+), 49 deletions(-)

New commits:
commit 0cbdbb4a41c2fda7cb196299f151f1396b3354c0
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Jun 19 09:40:42 2017 +0200

    fix lost read of m_bFormField field
    
    in commit 42922c40362f414ee06e65636f61798ef28cdcde
    "RTFDocumentImpl::popState: use switch here"
    
    found while running the unusedfields plugin
    
    Change-Id: I4be41dba976a13dc6d39155fb2a04d039dc0443a
    Reviewed-on: https://gerrit.libreoffice.org/38950
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 5fc97ab5053f..f9a4983dcf67 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -2194,60 +2194,63 @@ RTFError RTFDocumentImpl::popState()
     break;
     case Destination::DATAFIELD:
     {
-        if (&m_aStates.top().aDestinationText != m_aStates.top().pDestinationText)
-            break; // not for nested group
-        OString aStr = OUStringToOString(m_aStates.top().pDestinationText->makeStringAndClear(), aState.nCurrentEncoding);
-        // decode hex dump
-        OStringBuffer aBuf;
-        int b = 0, count = 2;
-        for (int i = 0; i < aStr.getLength(); ++i)
-        {
-            char ch = aStr[i];
-            if (ch != 0x0d && ch != 0x0a)
+        if (m_bFormField)
+        {
+            if (&m_aStates.top().aDestinationText != m_aStates.top().pDestinationText)
+                break; // not for nested group
+            OString aStr = OUStringToOString(m_aStates.top().pDestinationText->makeStringAndClear(), aState.nCurrentEncoding);
+            // decode hex dump
+            OStringBuffer aBuf;
+            int b = 0, count = 2;
+            for (int i = 0; i < aStr.getLength(); ++i)
             {
-                b = b << 4;
-                sal_Int8 parsed = RTFTokenizer::asHex(ch);
-                if (parsed == -1)
-                    return RTFError::HEX_INVALID;
-                b += parsed;
-                count--;
-                if (!count)
+                char ch = aStr[i];
+                if (ch != 0x0d && ch != 0x0a)
                 {
-                    aBuf.append((char)b);
-                    count = 2;
-                    b = 0;
+                    b = b << 4;
+                    sal_Int8 parsed = RTFTokenizer::asHex(ch);
+                    if (parsed == -1)
+                        return RTFError::HEX_INVALID;
+                    b += parsed;
+                    count--;
+                    if (!count)
+                    {
+                        aBuf.append((char)b);
+                        count = 2;
+                        b = 0;
+                    }
                 }
             }
-        }
-        aStr = aBuf.makeStringAndClear();
-
-        // ignore the first bytes
-        if (aStr.getLength() > 8)
-            aStr = aStr.copy(8);
-        // extract name
-        sal_Int32 nLength = aStr.toChar();
-        if (!aStr.isEmpty())
-            aStr = aStr.copy(1);
-        nLength = std::min(nLength, aStr.getLength());
-        OString aName = aStr.copy(0, nLength);
-        if (aStr.getLength() > nLength)
-            aStr = aStr.copy(nLength+1); // zero-terminated string
-        else
-            aStr.clear();
-        // extract default text
-        nLength = aStr.toChar();
-        if (!aStr.isEmpty())
-            aStr = aStr.copy(1);
-        auto pNValue = std::make_shared<RTFValue>(OStringToOUString(aName, aState.nCurrentEncoding));
-        m_aFormfieldSprms.set(NS_ooxml::LN_CT_FFData_name, pNValue);
-        if (nLength > 0)
-        {
-            OString aDefaultText = aStr.copy(0, std::min(nLength, aStr.getLength()));
-            auto pDValue = std::make_shared<RTFValue>(OStringToOUString(aDefaultText, aState.nCurrentEncoding));
-            m_aFormfieldSprms.set(NS_ooxml::LN_CT_FFTextInput_default, pDValue);
-        }
+            aStr = aBuf.makeStringAndClear();
+
+            // ignore the first bytes
+            if (aStr.getLength() > 8)
+                aStr = aStr.copy(8);
+            // extract name
+            sal_Int32 nLength = aStr.toChar();
+            if (!aStr.isEmpty())
+                aStr = aStr.copy(1);
+            nLength = std::min(nLength, aStr.getLength());
+            OString aName = aStr.copy(0, nLength);
+            if (aStr.getLength() > nLength)
+                aStr = aStr.copy(nLength+1); // zero-terminated string
+            else
+                aStr.clear();
+            // extract default text
+            nLength = aStr.toChar();
+            if (!aStr.isEmpty())
+                aStr = aStr.copy(1);
+            auto pNValue = std::make_shared<RTFValue>(OStringToOUString(aName, aState.nCurrentEncoding));
+            m_aFormfieldSprms.set(NS_ooxml::LN_CT_FFData_name, pNValue);
+            if (nLength > 0)
+            {
+                OString aDefaultText = aStr.copy(0, std::min(nLength, aStr.getLength()));
+                auto pDValue = std::make_shared<RTFValue>(OStringToOUString(aDefaultText, aState.nCurrentEncoding));
+                m_aFormfieldSprms.set(NS_ooxml::LN_CT_FFTextInput_default, pDValue);
+            }
 
-        m_bFormField = false;
+            m_bFormField = false;
+        }
     }
     break;
     case Destination::CREATIONTIME:


More information about the Libreoffice-commits mailing list