sc/inc/formularesult.hxx | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
New commits: commit ab2c9edeb47804840b5c50dd8198556e3ea9d29e Author: Eike Rathke <er...@redhat.com> Date: Tue Jan 31 20:40:47 2012 +0100 clone token in ScFormulaResult copy-ctor instead of referring Replaces commit e2b11f4fd79dce4116badb0ecf6477546ca5d0d4 Prevent excessive references to single token instance during fill. Because if not, we may run out of the 16-bit integer space to store reference count. Signed-off-by: Kohei Yoshida <kohei.yosh...@suse.com> diff --git a/sc/inc/formularesult.hxx b/sc/inc/formularesult.hxx index 2aa674c..444552f 100644 --- a/sc/inc/formularesult.hxx +++ b/sc/inc/formularesult.hxx @@ -41,6 +41,20 @@ class ScFormulaResult static const Multiline MULTILINE_FALSE = 1; static const Multiline MULTILINE_TRUE = 2; + // Clone token if the 16-bit only reference counter is nearing it's + // capacity during fill or copy&paste, leaving 4k for temporary passing + // around. (That should be enough for all times (TM) ;-) + static const sal_uInt16 MAX_TOKENREF_COUNT = 0xf000; + static void IncrementTokenRef( const formula::FormulaToken* & rp ) + { + if (rp) + { + if (rp->GetRef() >= MAX_TOKENREF_COUNT) + rp = rp->Clone(); + rp->IncRef(); + } + } + union { double mfValue; // double result direct for performance and memory consumption @@ -94,8 +108,12 @@ public: const ScMatrixFormulaCellToken* pMatFormula = r.GetMatrixFormulaCellToken(); if (pMatFormula) + { mpToken = new ScMatrixFormulaCellToken( *pMatFormula); - mpToken->IncRef(); + mpToken->IncRef(); + } + else + IncrementTokenRef( mpToken); } } else @@ -308,8 +326,7 @@ inline void ScFormulaResult::Assign( const ScFormulaResult & r ) inline void ScFormulaResult::SetToken( const formula::FormulaToken* p ) { ResetToDefaults(); - if (p) - p->IncRef(); + IncrementTokenRef( p); // Handle a result obtained from the interpreter to be assigned to a matrix // formula cell's ScMatrixFormulaCellToken. ScMatrixFormulaCellToken* pMatFormula = GetMatrixFormulaCellTokenNonConst(); _______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits