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

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Tue May 14 12:01:48 UTC 2019


 sw/source/uibase/utlui/prcntfld.cxx |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

New commits:
commit aa275f7af9cb79202c17835507aedce470eb762c
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue May 14 11:32:47 2019 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue May 14 14:00:44 2019 +0200

    Resolves: tdf#125229 divide by 0
    
    Change-Id: Iab34aa645252aea9c306f06814d75e405a2160e8
    Reviewed-on: https://gerrit.libreoffice.org/72278
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/source/uibase/utlui/prcntfld.cxx b/sw/source/uibase/utlui/prcntfld.cxx
index 6564e9be928a..0bd5199ee596 100644
--- a/sw/source/uibase/utlui/prcntfld.cxx
+++ b/sw/source/uibase/utlui/prcntfld.cxx
@@ -55,8 +55,6 @@ void SwPercentField::ShowPercent(bool bPercent)
 
     if (bPercent)
     {
-        int nCurrentWidth, nPercent;
-
         nOldValue = get_value();
 
         eOldUnit = m_pField->get_unit();
@@ -66,16 +64,16 @@ void SwPercentField::ShowPercent(bool bPercent)
         m_pField->set_unit(FieldUnit::PERCENT);
         m_pField->set_digits(0);
 
-        nCurrentWidth = MetricField::ConvertValue(nOldMin, 0, nOldDigits, eOldUnit, FieldUnit::TWIP);
+        int nCurrentWidth = MetricField::ConvertValue(nOldMin, 0, nOldDigits, eOldUnit, FieldUnit::TWIP);
         // round to 0.5 percent
-        nPercent = ((nCurrentWidth * 10) / nRefValue + 5) / 10;
+        int nPercent = nRefValue ? (((nCurrentWidth * 10) / nRefValue + 5) / 10) : 0;
 
         m_pField->set_range(std::max(1, nPercent), 100, FieldUnit::NONE);
         m_pField->set_increments(5, 10, FieldUnit::NONE);
         if (nOldValue != nLastValue)
         {
             nCurrentWidth = MetricField::ConvertValue(nOldValue, 0, nOldDigits, eOldUnit, FieldUnit::TWIP);
-            nPercent = ((nCurrentWidth * 10) / nRefValue + 5) / 10;
+            nPercent = nRefValue ? (((nCurrentWidth * 10) / nRefValue + 5) / 10) : 0;
             m_pField->set_value(nPercent, FieldUnit::NONE);
             nLastPercent = nPercent;
             nLastValue = nOldValue;
@@ -122,7 +120,7 @@ void SwPercentField::set_value(int nNewValue, FieldUnit eInUnit)
             int nValue = Convert(nNewValue, eInUnit, eOldUnit);
             nCurrentWidth = MetricField::ConvertValue(nValue, 0, nOldDigits, eOldUnit, FieldUnit::TWIP);
         }
-        nPercent = ((nCurrentWidth * 10) / nRefValue + 5) / 10;
+        nPercent = nRefValue ? (((nCurrentWidth * 10) / nRefValue + 5) / 10) : 0;
         m_pField->set_value(nPercent, FieldUnit::NONE);
     }
 }
@@ -221,7 +219,7 @@ int SwPercentField::Convert(int nValue, FieldUnit eInUnit, FieldUnit eOutUnit)
         else
             nCurrentWidth = MetricField::ConvertValue(nValue, 0, nOldDigits, eInUnit, FieldUnit::TWIP);
         // Round to 0.5 percent
-        return ((nCurrentWidth * 1000) / nRefValue + 5) / 10;
+        return nRefValue ? (((nCurrentWidth * 1000) / nRefValue + 5) / 10) : 0;
     }
 
     return MetricField::ConvertValue(nValue, 0, nOldDigits, eInUnit, eOutUnit);


More information about the Libreoffice-commits mailing list