[Libreoffice-commits] core.git: sw/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Feb 26 08:30:39 UTC 2019
sw/source/core/text/itradj.cxx | 14 +++++++-------
sw/source/core/text/porglue.cxx | 14 +++++++-------
sw/source/core/text/porglue.hxx | 6 +++---
3 files changed, 17 insertions(+), 17 deletions(-)
New commits:
commit 60c121981d829ef322718a69900a1585e87efb84
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Mon Feb 25 16:44:19 2019 +0100
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue Feb 26 09:30:17 2019 +0100
SwGluePortion::GetPrtGlue() can legitimately be larger than 'short`
At least during JunitTest_sw_unoapi_4
sw.SwXTextTable::com::sun::star::text::TextTable::TableColumnSeparators, some
SwFormatFrameSize is created with a width of USHRT_MAX ("Set USHRT_MAX as the
Table's default SSize") in SwDoc::InsertTable
(sw/source/core/docnode/ndtbl.cxx). In SwTabFrame::Format
(sw/source/core/layout/tabfrm.cxx) that leads to nWishedTableWidth with a value
near USHRT_MAX and substantially larger than nMax, causing nLeftSpacing to be a
large negative value in the text::HoriOrientation::CENTER case. That in turn
causes SwTextAdjuster::CalcRightMargin (sw/source/core/text/itradj.cxx) to
set
pRight->PrtWidth( sal_uInt16( nRealWidth - nPrtWidth ) );
with a value of 32768 (where pRight is a SwGluePortion). And a later call to
that SwGluePortion's GetPrtGlue would try to convert that 32768 to 'short',
getting flagged by Clang's -fsanitize=implicit-signed-integer-truncation.
In addition to changing GetPrtGlue (and MoveGlue) to use 'long' instead of
'short', drop some unncessary narrowing casts from client code.
Change-Id: I6a0d763acfad1fc3b550ec6107adf9f5429dd005
Reviewed-on: https://gerrit.libreoffice.org/68253
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/sw/source/core/text/itradj.cxx b/sw/source/core/text/itradj.cxx
index 14517379fc9a..047e26b6220e 100644
--- a/sw/source/core/text/itradj.cxx
+++ b/sw/source/core/text/itradj.cxx
@@ -435,7 +435,7 @@ SwTwips SwTextAdjuster::CalcKanaAdj( SwLineLayout* pCurrent )
if ( nKanaIdx == pCurrent->GetKanaComp().size() )
pCurrent->GetKanaComp().push_back( nNull );
- sal_uInt16 nRest;
+ long nRest;
if ( pPos->InTabGrp() )
{
@@ -759,9 +759,9 @@ void SwTextAdjuster::CalcDropAdjust()
if( pRight && pRight != pLeft )
{
// 5) Calculate nMinLeft. Who is the most to left?
- const sal_uInt16 nDropLineStart =
- sal_uInt16(GetLineStart()) + pLeft->Width() + pDropPor->Width();
- sal_uInt16 nMinLeft = nDropLineStart;
+ const auto nDropLineStart =
+ GetLineStart() + pLeft->Width() + pDropPor->Width();
+ auto nMinLeft = nDropLineStart;
for( sal_uInt16 i = 1; i < GetDropLines(); ++i )
{
if( NextLine() )
@@ -776,8 +776,8 @@ void SwTextAdjuster::CalcDropAdjust()
nMinLeft = 0;
else
{
- const sal_uInt16 nLineStart =
- sal_uInt16(GetLineStart()) + pMar->Width();
+ const auto nLineStart =
+ GetLineStart() + pMar->Width();
if( nMinLeft > nLineStart )
nMinLeft = nLineStart;
}
@@ -789,7 +789,7 @@ void SwTextAdjuster::CalcDropAdjust()
{
// The Glue is always passed from pLeft to pRight, so that
// the text moves to the left.
- const short nGlue = nDropLineStart - nMinLeft;
+ const auto nGlue = nDropLineStart - nMinLeft;
if( !nMinLeft )
pLeft->MoveAllGlue( pRight );
else
diff --git a/sw/source/core/text/porglue.cxx b/sw/source/core/text/porglue.cxx
index d35a5be48ef8..2b0db4e6a86a 100644
--- a/sw/source/core/text/porglue.cxx
+++ b/sw/source/core/text/porglue.cxx
@@ -107,13 +107,13 @@ void SwGluePortion::Paint( const SwTextPaintInfo &rInf ) const
}
}
-void SwGluePortion::MoveGlue( SwGluePortion *pTarget, const short nPrtGlue )
+void SwGluePortion::MoveGlue( SwGluePortion *pTarget, const long nPrtGlue )
{
- short nPrt = std::min( nPrtGlue, GetPrtGlue() );
+ auto nPrt = std::min( nPrtGlue, GetPrtGlue() );
if( 0 < nPrt )
{
- pTarget->AddPrtWidth( nPrt );
- SubPrtWidth( nPrt );
+ pTarget->AddPrtWidth( nPrt ); //TODO: overflow
+ SubPrtWidth( nPrt ); //TODO: overflow
}
}
@@ -187,8 +187,8 @@ void SwMarginPortion::AdjustRight( const SwLineLayout *pCurr )
pRight->MoveAllGlue( pLeft );
pRight = nullptr;
}
- sal_uInt16 nRightGlue = pRight && 0 < pRight->GetPrtGlue()
- ? sal_uInt16(pRight->GetPrtGlue()) : 0;
+ auto nRightGlue = pRight && 0 < pRight->GetPrtGlue()
+ ? pRight->GetPrtGlue() : 0;
// 2) balance left and right Glue
// But not for tabs ...
if( pLeft && nRightGlue && !pRight->InTabGrp() )
@@ -230,7 +230,7 @@ void SwMarginPortion::AdjustRight( const SwLineLayout *pCurr )
nRightGlue = nRightGlue - pPrev->PrtWidth();
// pPrev is moved behind pRight. For this the
// Glue value between pRight and pLeft gets balanced.
- pRight->MoveGlue( pLeft, short( pPrev->PrtWidth() ) );
+ pRight->MoveGlue( pLeft, pPrev->PrtWidth() );
// Now fix the linking of our portions.
SwLinePortion *pPrevPrev = pPrev->FindPrevPortion( pLeft );
pPrevPrev->SetNextPortion( pRight );
diff --git a/sw/source/core/text/porglue.hxx b/sw/source/core/text/porglue.hxx
index e02df21c784f..0a4ac95b1dc3 100644
--- a/sw/source/core/text/porglue.hxx
+++ b/sw/source/core/text/porglue.hxx
@@ -33,10 +33,10 @@ public:
void Join( SwGluePortion *pVictim );
- inline short GetPrtGlue() const;
+ inline long GetPrtGlue() const;
sal_uInt16 GetFixWidth() const { return nFixWidth; }
void SetFixWidth( const sal_uInt16 nNew ) { nFixWidth = nNew; }
- void MoveGlue( SwGluePortion *pTarget, const short nPrtGlue );
+ void MoveGlue( SwGluePortion *pTarget, const long nPrtGlue );
inline void MoveAllGlue( SwGluePortion *pTarget );
inline void MoveHalfGlue( SwGluePortion *pTarget );
inline void AdjFixWidth();
@@ -63,7 +63,7 @@ public:
void AdjustRight( const SwLineLayout* pCurr );
};
-inline short SwGluePortion::GetPrtGlue() const
+inline long SwGluePortion::GetPrtGlue() const
{ return Width() - nFixWidth; }
// The FixWidth MUST NEVER be larger than the accumulated width!
More information about the Libreoffice-commits
mailing list