Kaydet (Commit) f164c682 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Introduce dedicated SwXMLTableContext::MAX_WIDTH, replacing USHRT_MAX

For one, this should make it more obvious what the magic constant USHRT_MAX
meant in the context of SwXMLTableContext::m_nWidth (and shows that it should
arguably have value SAL_MAX_UINT16, not USHRT_MAX).

For another, at least some Android builds are stuck with a broken C library that
defines USHRT_MAX to be of type unsigned int instead of signed int, which caused
various -Wsign-compare that are removed as a side effect.

Change-Id: If2676954f4e7159b0c0d3656b8bc0186f0771e10
Reviewed-on: https://gerrit.libreoffice.org/48661Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst 506a1b1e
......@@ -1228,6 +1228,10 @@ public:
}
};
#if __cplusplus <= 201402
constexpr sal_Int32 SwXMLTableContext::MAX_WIDTH;
#endif
const SwXMLTableCell_Impl *SwXMLTableContext::GetCell( sal_uInt32 nRow,
sal_uInt32 nCol ) const
{
......@@ -1479,8 +1483,8 @@ void SwXMLTableContext::InsertColumn( sal_Int32 nWidth2, bool bRelWidth2,
if( nWidth2 < MINLAY )
nWidth2 = MINLAY;
else if( nWidth2 > USHRT_MAX )
nWidth2 = USHRT_MAX;
else if( nWidth2 > MAX_WIDTH )
nWidth2 = MAX_WIDTH;
m_aColumnWidths.emplace_back(nWidth2, bRelWidth2 );
if( (pDfltCellStyleName && !pDfltCellStyleName->isEmpty()) ||
m_pColumnDefaultCellStyleNames )
......@@ -2425,7 +2429,7 @@ void SwXMLTableContext::MakeTable_( SwTableBox *pBox )
// In this case, the columns get the correct width even if
// the sum of the relative widths is smaller than the available
// width in TWIP. Therefore, we can use the relative width.
m_nWidth = std::min<sal_Int32>(nRelWidth, USHRT_MAX);
m_nWidth = std::min(nRelWidth, MAX_WIDTH);
}
if( nRelWidth != m_nWidth && nRelWidth && nCols )
{
......@@ -2679,9 +2683,9 @@ void SwXMLTableContext::MakeTable()
// of the relative column widths as reference width.
// Unfortunately this works only if this sum interpreted as
// twip value is larger than the space that is available.
// We don't know that space, so we have to use USHRT_MAX, too.
// We don't know that space, so we have to use MAX_WIDTH, too.
// Even if a size is specified, it will be ignored!
m_nWidth = USHRT_MAX;
m_nWidth = MAX_WIDTH;
break;
default:
if( pSize )
......@@ -2695,14 +2699,14 @@ void SwXMLTableContext::MakeTable()
{
m_nWidth = pSize->GetWidth();
sal_Int32 const min = static_cast<sal_Int32>(
std::min<sal_uInt32>(GetColumnCount() * MINLAY, USHRT_MAX));
std::min<sal_uInt32>(GetColumnCount() * MINLAY, MAX_WIDTH));
if( m_nWidth < min )
{
m_nWidth = min;
}
else if( m_nWidth > USHRT_MAX )
else if( m_nWidth > MAX_WIDTH )
{
m_nWidth = USHRT_MAX;
m_nWidth = MAX_WIDTH;
}
m_bRelWidth = false;
}
......@@ -2712,7 +2716,7 @@ void SwXMLTableContext::MakeTable()
eHoriOrient = text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient
? text::HoriOrientation::NONE : text::HoriOrientation::FULL;
bSetHoriOrient = true;
m_nWidth = USHRT_MAX;
m_nWidth = MAX_WIDTH;
}
break;
}
......@@ -2722,7 +2726,7 @@ void SwXMLTableContext::MakeTable()
else
{
bSetHoriOrient = true;
m_nWidth = USHRT_MAX;
m_nWidth = MAX_WIDTH;
}
SwTableLine *pLine1 = m_pTableNode->GetTable().GetTabLines()[0U];
......
......@@ -91,6 +91,11 @@ class SwXMLTableContext : public XMLTextTableContext
sal_uInt32 m_nCurCol;
sal_Int32 m_nWidth;
// The maxiumum table width (i.e., maximum value for m_nWidth); musts be >= MINLAY and must also
// fit into ColumnWidthInfo::width (of type sal_uInt16), see e.g. the emplacement of
// MINLAY<=nWidht2<=MAX_WIDTH into m_aColumnWidths in SwXMLTableContext::InsertColumn:
static constexpr sal_Int32 MAX_WIDTH = SAL_MAX_UINT16;
SwTableBox *NewTableBox( const SwStartNode *pStNd,
SwTableLine *pUpper );
SwTableBox *MakeTableBox( SwTableLine *pUpper,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment