sw/source/filter/xml/xmltbli.cxx | 29 ++++++++++++++++++----------- sw/source/filter/xml/xmltbli.hxx | 5 +++++ 2 files changed, 23 insertions(+), 11 deletions(-)
New commits: commit f164c68296b66d534ed2c9de6da4c01e328959d9 Author: Stephan Bergmann <sberg...@redhat.com> Date: Fri Jan 26 09:37:04 2018 +0100 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/48661 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Michael Stahl <mst...@redhat.com> diff --git a/sw/source/filter/xml/xmltbli.cxx b/sw/source/filter/xml/xmltbli.cxx index 0d45824e43ca..61b629673256 100644 --- a/sw/source/filter/xml/xmltbli.cxx +++ b/sw/source/filter/xml/xmltbli.cxx @@ -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]; diff --git a/sw/source/filter/xml/xmltbli.hxx b/sw/source/filter/xml/xmltbli.hxx index 0f2fc81c8031..7a1868ed1dbe 100644 --- a/sw/source/filter/xml/xmltbli.hxx +++ b/sw/source/filter/xml/xmltbli.hxx @@ -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, commit 506a1b1e3d23e1e9cf0cf2e43d00447ccdcbbd92 Author: Stephan Bergmann <sberg...@redhat.com> Date: Fri Jan 26 08:47:28 2018 +0100 Assume this wants to cap GetColumnCount()*MINLAY <= m_nWidth <= USHRT_MAX ...even if GetColumnCount()*MINLAY > USHRT_MAX could ever be true, in which case it will now cap m_nWidth == USHRT_MAX. (The original code didn't have the cast of GetColumnCount() to sal_Int32, then 7e7c8a51f05ef2c7c56b26e27328ad4b30655740 "#80552#: bug fixes for progress" added a---presumably misplaced---C-style cast to the check (but not the assignment), presumably to silence some signed-vs-unsigned warning.) Change-Id: I2403ee3c5e8fe35ae2a7a7b7da9081a7fb7b59b1 Reviewed-on: https://gerrit.libreoffice.org/48654 Tested-by: Stephan Bergmann <sberg...@redhat.com> Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/sw/source/filter/xml/xmltbli.cxx b/sw/source/filter/xml/xmltbli.cxx index bb4e532b8e37..0d45824e43ca 100644 --- a/sw/source/filter/xml/xmltbli.cxx +++ b/sw/source/filter/xml/xmltbli.cxx @@ -59,6 +59,7 @@ #include <vcl/svapp.hxx> #include <ndtxt.hxx> +#include <algorithm> #include <vector> #include <memory> @@ -2693,9 +2694,11 @@ void SwXMLTableContext::MakeTable() else { m_nWidth = pSize->GetWidth(); - if( m_nWidth < static_cast<sal_Int32>(GetColumnCount()) * MINLAY ) + sal_Int32 const min = static_cast<sal_Int32>( + std::min<sal_uInt32>(GetColumnCount() * MINLAY, USHRT_MAX)); + if( m_nWidth < min ) { - m_nWidth = GetColumnCount() * MINLAY; + m_nWidth = min; } else if( m_nWidth > USHRT_MAX ) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits