[Libreoffice-commits] core.git: Branch 'libreoffice-5-3' - formula/source include/formula
Eike Rathke
erack at redhat.com
Fri Jan 6 00:48:04 UTC 2017
formula/source/core/api/FormulaCompiler.cxx | 2
include/formula/errorcodes.hxx | 67 ++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 1 deletion(-)
New commits:
commit 049862c9dd426eef74e229aee619facb98c7e7da
Author: Eike Rathke <erack at redhat.com>
Date: Thu Jan 5 18:23:04 2017 +0100
check "#ERRxxx!" constants for accepted error values, tdf#105024 follow-up
Change-Id: I9a11695710baa2f4e022c8e07f01b962cfabe2e7
(cherry picked from commit 6b89bcf85a911d043c9d93e843be12e6f23adedd)
Reviewed-on: https://gerrit.libreoffice.org/32763
Reviewed-by: Eike Rathke <erack at redhat.com>
Tested-by: Eike Rathke <erack at redhat.com>
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 9e23149..66c92fb 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -1192,7 +1192,7 @@ FormulaError FormulaCompiler::GetErrorConstant( const OUString& rName ) const
if (rName.startsWithIgnoreAsciiCase("#ERR") && rName[rName.getLength()-1] == '!')
{
sal_uInt32 nErr = rName.copy( 4, rName.getLength() - 5).toUInt32();
- if (0 < nErr && nErr <= SAL_MAX_UINT16)
+ if (0 < nErr && nErr <= SAL_MAX_UINT16 && isPublishedFormulaError(static_cast<FormulaError>(nErr)))
nError = static_cast<FormulaError>(nErr);
}
}
diff --git a/include/formula/errorcodes.hxx b/include/formula/errorcodes.hxx
index 329be0d..2af9b11 100644
--- a/include/formula/errorcodes.hxx
+++ b/include/formula/errorcodes.hxx
@@ -119,6 +119,73 @@ inline FormulaError GetDoubleErrorValue( double fVal )
return (FormulaError)(nErr & 0x0000ffff);
}
+/** Error values that are accepted as detailed "#ERRxxx!" constants.
+
+ Used in FormulaCompiler::GetErrorConstant() to prevent users from inventing
+ arbitrary values that already have or later might get a significant meaning.
+ */
+inline bool isPublishedFormulaError( FormulaError nErr )
+{
+ // Every value has to be handled explicitly, do not add a default case to
+ // let the compiler complain if a value is missing.
+ switch (nErr)
+ {
+ case FormulaError::NONE:
+ return false;
+
+ case FormulaError::IllegalChar:
+ case FormulaError::IllegalArgument:
+ case FormulaError::IllegalFPOperation:
+ case FormulaError::IllegalParameter:
+ case FormulaError::IllegalJump:
+ case FormulaError::Separator:
+ case FormulaError::Pair:
+ case FormulaError::PairExpected:
+ case FormulaError::OperatorExpected:
+ case FormulaError::VariableExpected:
+ case FormulaError::ParameterExpected:
+ case FormulaError::CodeOverflow:
+ case FormulaError::StringOverflow:
+ case FormulaError::StackOverflow:
+ case FormulaError::UnknownState:
+ case FormulaError::UnknownVariable:
+ case FormulaError::UnknownOpCode:
+ case FormulaError::UnknownStackVariable:
+ case FormulaError::NoValue:
+ case FormulaError::UnknownToken:
+ case FormulaError::NoCode:
+ case FormulaError::CircularReference:
+ case FormulaError::NoConvergence:
+ case FormulaError::NoRef:
+ case FormulaError::NoName:
+ case FormulaError::DoubleRef:
+ return true;
+
+ case FormulaError::TrackFromCircRef:
+ case FormulaError::CellNoValue:
+ return false;
+
+ case FormulaError::NoAddin:
+ case FormulaError::NoMacro:
+ case FormulaError::DivisionByZero:
+ case FormulaError::NestedArray:
+ return true;
+
+ case FormulaError::NotNumericString:
+ case FormulaError::JumpMatHasResult:
+ case FormulaError::ElementNaN:
+ case FormulaError::RetryCircular:
+ return false;
+
+ case FormulaError::MatrixSize:
+ return true;
+
+ case FormulaError::NotAvailable:
+ return false;
+ }
+ return false;
+}
+
#endif // INCLUDED_FORMULA_ERRORCODES_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list