Kaydet (Commit) 54ba9587 authored tarafından Caolán McNamara's avatar Caolán McNamara

coverity#1202781 Division or modulo by zero

Change-Id: I2908c57badd079c8f19c679f40ed815ce2cba374
üst b7e999e2
......@@ -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;
}
......
/* -*- 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: */
......@@ -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();
}
......
......@@ -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();
......
......@@ -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)
{
......
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