summaryrefslogtreecommitdiff
path: root/sc/source/core/inc/interpre.hxx
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2014-06-05 16:34:08 +0200
committerEike Rathke <erack@redhat.com>2014-06-05 16:41:41 +0200
commit14ce27cc045bd9bcbbfa3eac56cd99f2be08de1f (patch)
tree7aae62e8bf7dbbca3665dc2d6bca2b02c8c62f3f /sc/source/core/inc/interpre.hxx
parent199eb08be994ef968eb38f4966bc27ef1756d382 (diff)
unify the handling of string position arguments, fdo#75971 related
Only two text functions had the full set of checks as introduced by the fix for fdo#75971. Let all text functions check their arguments in the same way. Additionally this will ease a transition to accept string lengths >64k in spreadsheet functions as now we have only one place that checks for SAL_MAX_UINT16 instead of having that scattered all over the place. Change-Id: I454e617a59d0b3c2ca725047e7f8c7370bc0bb1f
Diffstat (limited to 'sc/source/core/inc/interpre.hxx')
-rw-r--r--sc/source/core/inc/interpre.hxx48
1 files changed, 48 insertions, 0 deletions
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 6022c8ea7f6b..642699a5a0be 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -368,6 +368,24 @@ void ScTableOp(); // repeated operations
void SetMaxIterationCount(sal_uInt16 n);
inline void CurFmtToFuncFmt()
{ nFuncFmtType = nCurFmtType; nFuncFmtIndex = nCurFmtIndex; }
+
+/** Check if a double is suitable as string position or length argument.
+
+ If fVal is Inf or NaN it is changed to -1, if it is less than 0 it is
+ sanitized to 0, if it is greater than some implementation defined max
+ string length it is sanitized to that max.
+
+ @return TRUE if double value fVal is suitable as string argument and was
+ not sanitized.
+ FALSE if not and fVal was adapted.
+ */
+inline bool CheckStringPositionArgument( double & fVal );
+
+/** Obtain a double suitable as string position or length argument.
+ Returns -1 if the number is Inf or NaN or less than 0 or greater than some
+ implementation defined max string length. */
+inline double GetStringPositionArgument();
+
// Check for String overflow of rResult+rAdd and set error and erase rResult
// if so. Return true if ok, false if overflow
inline bool CheckStringResultLen( OUString& rResult, const OUString& rAdd );
@@ -921,6 +939,36 @@ inline bool ScInterpreter::MustHaveParamCountMin( short nAct, short nMin )
return false;
}
+inline bool ScInterpreter::CheckStringPositionArgument( double & fVal )
+{
+ if (!rtl::math::isFinite( fVal))
+ {
+ fVal = -1.0;
+ return false;
+ }
+ else if (fVal < 0.0)
+ {
+ fVal = 0.0;
+ return false;
+ }
+ else if (fVal > SAL_MAX_UINT16)
+ {
+ fVal = static_cast<double>(SAL_MAX_UINT16);
+ return false;
+ }
+ return true;
+}
+
+inline double ScInterpreter::GetStringPositionArgument()
+{
+ double fVal = rtl::math::approxFloor( GetDouble());
+ if (!CheckStringPositionArgument( fVal))
+ {
+ fVal = -1.0;
+ }
+ return fVal;
+}
+
inline bool ScInterpreter::CheckStringResultLen( OUString& rResult, const OUString& rAdd )
{
if ( rResult.getLength() + rAdd.getLength() > SAL_MAX_UINT16 )