[Libreoffice-commits] .: sc/inc sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Wed Jan 19 10:13:41 PST 2011
sc/inc/queryparam.hxx | 6 ++++++
sc/source/core/tool/doubleref.cxx | 26 ++++++++------------------
sc/source/core/tool/interpr1.cxx | 21 +++++++++++++++++++++
sc/source/core/tool/queryparam.cxx | 17 +++++++++++++++++
4 files changed, 52 insertions(+), 18 deletions(-)
New commits:
commit 9932e2dad520525122396bf9f9674d847a16a2ae
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Wed Jan 19 13:05:27 2011 -0500
Ported calc-formula-db-function-fix.diff from the build repo.
This patch fixes n#594332 and n#595713.
diff --git a/sc/inc/queryparam.hxx b/sc/inc/queryparam.hxx
index 62a4a6e..9b6b067 100644
--- a/sc/inc/queryparam.hxx
+++ b/sc/inc/queryparam.hxx
@@ -51,6 +51,8 @@ struct ScQueryParamBase
virtual ~ScQueryParamBase();
+ virtual bool IsValidFieldIndex() const;
+
SC_DLLPUBLIC SCSIZE GetEntryCount() const;
SC_DLLPUBLIC ScQueryEntry& GetEntry(SCSIZE n) const;
void Resize(SCSIZE nNew);
@@ -130,6 +132,8 @@ struct ScDBQueryParamInternal : public ScDBQueryParamBase, public ScQueryParamTa
{
ScDBQueryParamInternal();
virtual ~ScDBQueryParamInternal();
+
+ virtual bool IsValidFieldIndex() const;
};
// ============================================================================
@@ -140,6 +144,8 @@ struct ScDBQueryParamMatrix : public ScDBQueryParamBase
ScDBQueryParamMatrix();
virtual ~ScDBQueryParamMatrix();
+
+ virtual bool IsValidFieldIndex() const;
};
#endif
diff --git a/sc/source/core/tool/doubleref.cxx b/sc/source/core/tool/doubleref.cxx
index 34862ae..a4d5d1f 100644
--- a/sc/source/core/tool/doubleref.cxx
+++ b/sc/source/core/tool/doubleref.cxx
@@ -327,11 +327,13 @@ SCSIZE ScDBInternalRange::getVisibleDataCellCount() const
OUString ScDBInternalRange::getString(SCCOL nCol, SCROW nRow) const
{
- String aStr;
+ OUString aStr;
const ScAddress& s = maRange.aStart;
- // #i109200# this is used in formula calculation, use GetInputString, not GetString
- // (consistent with ScDBInternalRange::getCellString)
- getDoc()->GetInputString(s.Col() + nCol, s.Row() + nRow, maRange.aStart.Tab(), aStr);
+ ScBaseCell* pCell = getDoc()->GetCell(ScAddress(s.Col() + nCol, s.Row() + nRow, maRange.aStart.Tab()));
+ if (!pCell)
+ return aStr;
+
+ getCellString(aStr, pCell);
return aStr;
}
@@ -344,15 +346,11 @@ SCCOL ScDBInternalRange::findFieldColumn(SCCOL nIndex) const
{
const ScRange& rRange = getRange();
const ScAddress& s = rRange.aStart;
- const ScAddress& e = rRange.aEnd;
SCCOL nDBCol1 = s.Col();
- SCCOL nDBCol2 = e.Col();
-
- if ( nIndex <= 0 || nIndex > (nDBCol2 - nDBCol1 + 1) )
- return nDBCol1;
- return Min(nDBCol2, static_cast<SCCOL>(nDBCol1 + nIndex - 1));
+ // Don't handle out-of-bound condition here. We'll do that later.
+ return nIndex + nDBCol1 - 1;
}
sal_uInt16 ScDBInternalRange::getCellString(OUString& rStr, ScBaseCell* pCell) const
@@ -514,14 +512,6 @@ SCCOL ScDBExternalRange::getFirstFieldColumn() const
SCCOL ScDBExternalRange::findFieldColumn(SCCOL nIndex) const
{
- if (nIndex < 1)
- // 1st field
- return 0;
-
- if (nIndex > mnCols)
- // last field
- return mnCols - 1;
-
return nIndex - 1;
}
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index c26abb0..e59601c 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -6226,6 +6226,11 @@ void ScInterpreter::DBIterator( ScIterFunc eFunc )
auto_ptr<ScDBQueryParamBase> pQueryParam( GetDBParams(bMissingField) );
if (pQueryParam.get())
{
+ if (!pQueryParam->IsValidFieldIndex())
+ {
+ SetError(errNoValue);
+ return;
+ }
ScDBQueryDataIterator aValIter(pDok, pQueryParam.release());
ScDBQueryDataIterator::Value aValue;
if ( aValIter.GetFirst(aValue) && !aValue.mnError )
@@ -6302,6 +6307,7 @@ void ScInterpreter::ScDBCount()
// return empty cells, which would mean to adapt all callers of
// iterators.
ScDBQueryParamInternal* p = static_cast<ScDBQueryParamInternal*>(pQueryParam.get());
+ p->nCol2 = p->nCol1; // Don't forget to select only one column.
SCTAB nTab = p->nTab;
// ScQueryCellIterator doesn't make use of ScDBQueryParamBase::mnField,
// so the source range has to be restricted, like before the introduction
@@ -6318,6 +6324,11 @@ void ScInterpreter::ScDBCount()
}
else
{ // count only matching records with a value in the "result" field
+ if (!pQueryParam->IsValidFieldIndex())
+ {
+ SetError(errNoValue);
+ return;
+ }
ScDBQueryDataIterator aValIter( pDok, pQueryParam.release());
ScDBQueryDataIterator::Value aValue;
if ( aValIter.GetFirst(aValue) && !aValue.mnError )
@@ -6344,6 +6355,11 @@ void ScInterpreter::ScDBCount2()
auto_ptr<ScDBQueryParamBase> pQueryParam( GetDBParams(bMissingField) );
if (pQueryParam.get())
{
+ if (!pQueryParam->IsValidFieldIndex())
+ {
+ SetError(errNoValue);
+ return;
+ }
ULONG nCount = 0;
pQueryParam->mbSkipString = false;
ScDBQueryDataIterator aValIter( pDok, pQueryParam.release());
@@ -6405,6 +6421,11 @@ void ScInterpreter::GetDBStVarParams( double& rVal, double& rValCount )
auto_ptr<ScDBQueryParamBase> pQueryParam( GetDBParams(bMissingField) );
if (pQueryParam.get())
{
+ if (!pQueryParam->IsValidFieldIndex())
+ {
+ SetError(errNoValue);
+ return;
+ }
ScDBQueryDataIterator aValIter(pDok, pQueryParam.release());
ScDBQueryDataIterator::Value aValue;
if (aValIter.GetFirst(aValue) && !aValue.mnError)
diff --git a/sc/source/core/tool/queryparam.cxx b/sc/source/core/tool/queryparam.cxx
index 429bdc9..9821857 100644
--- a/sc/source/core/tool/queryparam.cxx
+++ b/sc/source/core/tool/queryparam.cxx
@@ -58,6 +58,11 @@ ScQueryParamBase::~ScQueryParamBase()
{
}
+bool ScQueryParamBase::IsValidFieldIndex() const
+{
+ return true;
+}
+
SCSIZE ScQueryParamBase::GetEntryCount() const
{
return maEntries.size();
@@ -367,6 +372,11 @@ ScDBQueryParamInternal::~ScDBQueryParamInternal()
{
}
+bool ScDBQueryParamInternal::IsValidFieldIndex() const
+{
+ return nCol1 <= mnField && mnField <= nCol2;
+}
+
// ============================================================================
ScDBQueryParamMatrix::ScDBQueryParamMatrix() :
@@ -374,6 +384,13 @@ ScDBQueryParamMatrix::ScDBQueryParamMatrix() :
{
}
+bool ScDBQueryParamMatrix::IsValidFieldIndex() const
+{
+ SCSIZE nC, nR;
+ mpMatrix->GetDimensions(nC, nR);
+ return 0 <= mnField && mnField <= static_cast<SCCOL>(nC);
+}
+
ScDBQueryParamMatrix::~ScDBQueryParamMatrix()
{
}
More information about the Libreoffice-commits
mailing list