[Libreoffice-commits] core.git: sw/source

Caolán McNamara caolanm at redhat.com
Wed May 16 07:54:59 UTC 2018


 sw/source/ui/misc/pggrid.cxx |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

New commits:
commit 414226273aa4dc0e2d06cbd482ffac37ea9338c3
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue May 15 15:34:05 2018 +0100

    coverity#1430102 Division or modulo by zero
    
    Change-Id: I2db581b3f30713edaca4ec11f85343c436c54fae
    Reviewed-on: https://gerrit.libreoffice.org/54380
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/source/ui/misc/pggrid.cxx b/sw/source/ui/misc/pggrid.cxx
index 24b8c06aaef6..d143f35d123f 100644
--- a/sw/source/ui/misc/pggrid.cxx
+++ b/sw/source/ui/misc/pggrid.cxx
@@ -386,7 +386,9 @@ IMPL_LINK(SwTextGridPage, CharorLineChangedHdl, SpinField&, rField, void)
     {
         if(m_pCharsPerLineNF == &rField)
         {
-            long nWidth = static_cast<long>(m_aPageSize.Width() / m_pCharsPerLineNF->GetValue());
+            auto nValue = m_pCharsPerLineNF->GetValue();
+            assert(nValue && "div-by-zero");
+            auto nWidth = m_aPageSize.Width() / nValue;
             m_pTextSizeMF->SetValue(m_pTextSizeMF->Normalize(nWidth), FUNIT_TWIP);
             //prevent rounding errors in the MetricField by saving the used value
             m_nRubyUserValue = nWidth;
@@ -409,7 +411,7 @@ IMPL_LINK(SwTextGridPage, CharorLineChangedHdl, SpinField&, rField, void)
         {
             auto nValue = m_pLinesPerPageNF->GetValue();
             assert(nValue && "div-by-zero");
-            long nHeight = static_cast< sal_Int32 >(m_aPageSize.Height() / nValue);
+            auto nHeight = m_aPageSize.Height() / nValue;
             m_pTextSizeMF->SetValue(m_pTextSizeMF->Normalize(nHeight), FUNIT_TWIP);
             m_pRubySizeMF->SetValue(0, FUNIT_TWIP);
             SetLinesOrCharsRanges( *m_pLinesRangeFT , m_pLinesPerPageNF->GetMax() );
@@ -421,7 +423,7 @@ IMPL_LINK(SwTextGridPage, CharorLineChangedHdl, SpinField&, rField, void)
         {
             auto nValue = m_pCharsPerLineNF->GetValue();
             assert(nValue && "div-by-zero");
-            long nWidth = static_cast< sal_Int32 >(m_aPageSize.Width() / nValue);
+            auto nWidth = m_aPageSize.Width() / nValue;
             m_pCharWidthMF->SetValue(m_pCharWidthMF->Normalize(nWidth), FUNIT_TWIP);
             SetLinesOrCharsRanges( *m_pCharsRangeFT , m_pCharsPerLineNF->GetMax() );
         }


More information about the Libreoffice-commits mailing list