From 055c8cc676921176e2b9df76bd0e09bacab1d80b Mon Sep 17 00:00:00 2001 From: Winfried Donkers Date: Fri, 3 Mar 2017 16:48:38 +0100 Subject: Check for divide by zero in Calc function SLN. Plus use correct prefixes for variable names. Change-Id: Ia60117bec22eb305cb351a2e5fa0e757b4897139 Reviewed-on: https://gerrit.libreoffice.org/34872 Tested-by: Jenkins Reviewed-by: Eike Rathke --- sc/qa/unit/data/functions/financial/fods/sln.fods | 20 ++++++++++++++++---- sc/source/core/tool/interpr2.cxx | 13 +++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) (limited to 'sc') diff --git a/sc/qa/unit/data/functions/financial/fods/sln.fods b/sc/qa/unit/data/functions/financial/fods/sln.fods index 88bad0ec6cb1..05a85c3f9b80 100644 --- a/sc/qa/unit/data/functions/financial/fods/sln.fods +++ b/sc/qa/unit/data/functions/financial/fods/sln.fods @@ -2526,10 +2526,22 @@ - - - - + + Err:502 + + + Err:502 + + + TRUE + + + =SLN(100,10,0) + + + prevent #div/0! Error + + diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index a33aa336917c..a5dae57722fe 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -1895,10 +1895,15 @@ void ScInterpreter::ScSLN() nFuncFmtType = css::util::NumberFormat::CURRENCY; if ( MustHaveParamCount( GetByte(), 3 ) ) { - double nTimeLength = GetDouble(); - double nRest = GetDouble(); - double nValue = GetDouble(); - PushDouble((nValue - nRest) / nTimeLength); + double fTimeLength = GetDouble(); + if ( fTimeLength == 0.0 ) + PushIllegalArgument(); + else + { + double fRest = GetDouble(); + double fValue = GetDouble(); + PushDouble((fValue - fRest) / fTimeLength); + } } } -- cgit