diff options
author | Caolán McNamara <caolanm@redhat.com> | 2014-10-29 09:44:32 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-10-29 10:40:09 +0000 |
commit | 54ba9587c0f1d3b5206742339af4907047fb4748 (patch) | |
tree | 3526b06449a74b5bca07aa4cdb141abc8f535c5b /sw | |
parent | b7e999e2e9df272e8542c6a32486b2cc1a058f15 (diff) |
coverity#1202781 Division or modulo by zero
Change-Id: I2908c57badd079c8f19c679f40ed815ce2cba374
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/docnode/ndtbl.cxx | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index d5956b7e2001..25747f38a3fe 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -92,6 +92,7 @@ #include <rootfrm.hxx> #include <fldupde.hxx> #include <switerator.hxx> +#include <o3tl/numeric.hxx> #include <boost/foreach.hpp> #ifdef DBG_UTIL @@ -2948,7 +2949,7 @@ const SwTableBox* SwCollectTblLineBoxes::GetBoxOfPos( const SwTableBox& rBox ) bool SwCollectTblLineBoxes::Resize( sal_uInt16 nOffset, sal_uInt16 nOldWidth ) { - sal_uInt16 n; + size_t n; if( !aPosArr.empty() ) { @@ -2967,13 +2968,20 @@ bool SwCollectTblLineBoxes::Resize( sal_uInt16 nOffset, sal_uInt16 nOldWidth ) aPosArr.erase( aPosArr.begin(), aPosArr.begin() + n ); m_Boxes.erase(m_Boxes.begin(), m_Boxes.begin() + n); - // Adapt the positions to the new Size - for( n = 0; n < aPosArr.size(); ++n ) + size_t nSize = aPosArr.size(); + if (nSize) { - sal_uLong nSize = nWidth; - nSize *= ( aPosArr[ n ] - nOffset ); - nSize /= nOldWidth; - aPosArr[ n ] = sal_uInt16( nSize ); + if (nOldWidth == 0) + throw o3tl::divide_by_zero(); + + // Adapt the positions to the new Size + for( n = 0; n < nSize; ++n ) + { + sal_uLong nSize = nWidth; + nSize *= ( aPosArr[ n ] - nOffset ); + nSize /= nOldWidth; + aPosArr[ n ] = sal_uInt16( nSize ); + } } } return !aPosArr.empty(); |