diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-04-09 22:23:23 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-04-10 00:50:53 +0200 |
commit | 8e9de1ad055d1d8f41a6cf6d8cea245463f61d40 (patch) | |
tree | 0991fb87670cea71ef4d243574606da6c00fc9a3 /linguistic | |
parent | 36883a9fa5f18ff8f38e2b12e85d8f58d49dd1b5 (diff) |
Fix double-clear of clearable mutex guard
Change-Id: I91f04cae91cbb5510f70baaf8c31ecc59f6402c7
Reviewed-on: https://gerrit.libreoffice.org/70479
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'linguistic')
-rw-r--r-- | linguistic/source/gciterator.cxx | 90 |
1 files changed, 48 insertions, 42 deletions
diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx index 325af32849bd..62322ae67032 100644 --- a/linguistic/source/gciterator.cxx +++ b/linguistic/source/gciterator.cxx @@ -611,57 +611,63 @@ void GrammarCheckingIterator::DequeueAndCheck() const bool bModified = xFlatPara->isModified(); if (!bModified) { - // ---- THREAD SAFE START ---- - ::osl::ClearableGuard< ::osl::Mutex > aGuard( MyMutex::get() ); - - sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex; - sal_Int32 nSuggestedEnd = GetSuggestedEndOfSentence( aCurTxt, nStartPos, aCurLocale ); - DBG_ASSERT( (nSuggestedEnd == 0 && aCurTxt.isEmpty()) || nSuggestedEnd > nStartPos, - "nSuggestedEndOfSentencePos calculation failed?" ); - linguistic2::ProofreadingResult aRes; - uno::Reference< linguistic2::XProofreader > xGC( GetGrammarChecker( aCurLocale ), uno::UNO_QUERY ); - if (xGC.is()) + // ---- THREAD SAFE START ---- { - aGuard.clear(); - uno::Sequence<beans::PropertyValue> const aProps( - lcl_makeProperties(xFlatPara)); - aRes = xGC->doProofreading( aCurDocId, aCurTxt, - aCurLocale, nStartPos, nSuggestedEnd, aProps ); - - //!! work-around to prevent looping if the grammar checker - //!! failed to properly identify the sentence end - if ( - aRes.nBehindEndOfSentencePosition <= nStartPos && - aRes.nBehindEndOfSentencePosition != nSuggestedEnd - ) + osl::ClearableMutexGuard aGuard(MyMutex::get()); + + sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex; + sal_Int32 nSuggestedEnd + = GetSuggestedEndOfSentence(aCurTxt, nStartPos, aCurLocale); + DBG_ASSERT((nSuggestedEnd == 0 && aCurTxt.isEmpty()) + || nSuggestedEnd > nStartPos, + "nSuggestedEndOfSentencePos calculation failed?"); + + uno::Reference<linguistic2::XProofreader> xGC( + GetGrammarChecker(aCurLocale), uno::UNO_QUERY); + if (xGC.is()) + { + aGuard.clear(); + uno::Sequence<beans::PropertyValue> const aProps( + lcl_makeProperties(xFlatPara)); + aRes = xGC->doProofreading(aCurDocId, aCurTxt, aCurLocale, + nStartPos, nSuggestedEnd, aProps); + + //!! work-around to prevent looping if the grammar checker + //!! failed to properly identify the sentence end + if (aRes.nBehindEndOfSentencePosition <= nStartPos + && aRes.nBehindEndOfSentencePosition != nSuggestedEnd) + { + SAL_WARN( + "linguistic", + "!! Grammarchecker failed to provide end of sentence !!"); + aRes.nBehindEndOfSentencePosition = nSuggestedEnd; + } + + aRes.xFlatParagraph = xFlatPara; + aRes.nStartOfSentencePosition = nStartPos; + } + else { - SAL_WARN( "linguistic", "!! Grammarchecker failed to provide end of sentence !!" ); + // no grammar checker -> no error + // but we need to provide the data below in order to continue with the next sentence + aRes.aDocumentIdentifier = aCurDocId; + aRes.xFlatParagraph = xFlatPara; + aRes.aText = aCurTxt; + aRes.aLocale = aCurLocale; + aRes.nStartOfSentencePosition = nStartPos; aRes.nBehindEndOfSentencePosition = nSuggestedEnd; } + aRes.nStartOfNextSentencePosition + = lcl_SkipWhiteSpaces(aCurTxt, aRes.nBehindEndOfSentencePosition); + aRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces( + aCurTxt, aRes.nStartOfNextSentencePosition); - aRes.xFlatParagraph = xFlatPara; - aRes.nStartOfSentencePosition = nStartPos; + //guard has to be cleared as ProcessResult calls out of this class } - else - { - // no grammar checker -> no error - // but we need to provide the data below in order to continue with the next sentence - aRes.aDocumentIdentifier = aCurDocId; - aRes.xFlatParagraph = xFlatPara; - aRes.aText = aCurTxt; - aRes.aLocale = aCurLocale; - aRes.nStartOfSentencePosition = nStartPos; - aRes.nBehindEndOfSentencePosition = nSuggestedEnd; - } - aRes.nStartOfNextSentencePosition = lcl_SkipWhiteSpaces( aCurTxt, aRes.nBehindEndOfSentencePosition ); - aRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces( aCurTxt, aRes.nStartOfNextSentencePosition ); - - //guard has to be cleared as ProcessResult calls out of this class - aGuard.clear(); - ProcessResult( aRes, xFPIterator, aFPEntryItem.m_bAutomatic ); // ---- THREAD SAFE END ---- + ProcessResult( aRes, xFPIterator, aFPEntryItem.m_bAutomatic ); } else { |