summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2019-05-14 11:32:47 +0100
committerCaolán McNamara <caolanm@redhat.com>2019-05-14 14:00:44 +0200
commitaa275f7af9cb79202c17835507aedce470eb762c (patch)
tree4bec7e4aa7412261062bc11e23fd1aec88315997 /sw
parent93abdf39b01bb7b404dc09ef37369a4350fb0d10 (diff)
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@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/uibase/utlui/prcntfld.cxx12
1 files changed, 5 insertions, 7 deletions
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);