summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2014-10-29 09:44:32 +0000
committerCaolán McNamara <caolanm@redhat.com>2014-10-29 10:40:09 +0000
commit54ba9587c0f1d3b5206742339af4907047fb4748 (patch)
tree3526b06449a74b5bca07aa4cdb141abc8f535c5b
parentb7e999e2e9df272e8542c6a32486b2cc1a058f15 (diff)
coverity#1202781 Division or modulo by zero
Change-Id: I2908c57badd079c8f19c679f40ed815ce2cba374
-rw-r--r--filter/source/graphicfilter/epict/epict.cxx4
-rw-r--r--include/o3tl/numeric.hxx28
-rw-r--r--svtools/source/misc/imap.cxx4
-rw-r--r--sw/source/core/docnode/ndtbl.cxx22
-rw-r--r--writerfilter/source/dmapper/DomainMapperTableManager.cxx3
5 files changed, 49 insertions, 12 deletions
diff --git a/filter/source/graphicfilter/epict/epict.cxx b/filter/source/graphicfilter/epict/epict.cxx
index 3fe0455e2e3f..69407f6b4a82 100644
--- a/filter/source/graphicfilter/epict/epict.cxx
+++ b/filter/source/graphicfilter/epict/epict.cxx
@@ -34,7 +34,7 @@
#include <vcl/msgbox.hxx>
#include <vcl/gdimtf.hxx>
#include <tools/bigint.hxx>
-
+#include <o3tl/numeric.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <boost/scoped_array.hpp>
@@ -1758,7 +1758,7 @@ void PictWriter::WriteOpcodes( const GDIMetaFile & rMTF )
if (nLength > 0)
{
if (nNormSize == 0)
- throw std::runtime_error("divide by zero");
+ throw o3tl::divide_by_zero();
for (sal_Int32 i = 0; i < nLength; ++i)
pDXAry[ i ] = pDXAry[ i ] * ( (long)pA->GetWidth() ) / nNormSize;
}
diff --git a/include/o3tl/numeric.hxx b/include/o3tl/numeric.hxx
new file mode 100644
index 000000000000..09f67f53d5d3
--- /dev/null
+++ b/include/o3tl/numeric.hxx
@@ -0,0 +1,28 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_O3TL_NUMERIC_HXX
+#define INCLUDED_O3TL_NUMERIC_HXX
+
+#include <stdexcept>
+
+namespace o3tl
+{
+ struct divide_by_zero : public std::runtime_error
+ {
+ explicit divide_by_zero()
+ : std::runtime_error("divide by zero")
+ {
+ }
+ };
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svtools/source/misc/imap.cxx b/svtools/source/misc/imap.cxx
index 647f3e8fbc31..4eebd55d9638 100644
--- a/svtools/source/misc/imap.cxx
+++ b/svtools/source/misc/imap.cxx
@@ -22,7 +22,7 @@
#include <vcl/svapp.hxx>
#include <vcl/mapmod.hxx>
#include <vcl/window.hxx>
-
+#include <o3tl/numeric.hxx>
#include <svl/urihelper.hxx>
#include <svtools/imap.hxx>
#include <svtools/imapobj.hxx>
@@ -384,7 +384,7 @@ void IMapCircleObject::Scale( const Fraction& rFracX, const Fraction& rFracY )
}
if (!aAverage.GetDenominator())
- throw std::runtime_error("divide by zero");
+ throw o3tl::divide_by_zero();
nRadius = ( nRadius * aAverage.GetNumerator() ) / aAverage.GetDenominator();
}
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();
diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
index cbb32a8a60df..f4bc4ddd12d1 100644
--- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
@@ -30,6 +30,7 @@
#include <com/sun/star/text/TableColumnSeparator.hpp>
#include <com/sun/star/text/VertOrientation.hpp>
#include <com/sun/star/text/WritingMode2.hpp>
+#include <o3tl/numeric.hxx>
#include <ooxml/resourceids.hxx>
#include <dmapperLoggers.hxx>
#include <dmapper/DomainMapper.hxx>
@@ -791,7 +792,7 @@ void DomainMapperTableManager::endOfRowAction()
if (nWidthsBound)
{
if (nFullWidthRelative == 0)
- throw std::range_error("divide by zero");
+ throw o3tl::divide_by_zero();
for (sal_uInt32 i = 0; i < nWidthsBound; ++i)
{