[Libreoffice-commits] .: Branch 'libreoffice-3-4' - 2 commits - sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Tue May 17 21:01:51 PDT 2011
sc/source/ui/docshell/autostyl.cxx | 66 +++++++++++++++++++++++++++----------
sc/source/ui/unoobj/fmtuno.cxx | 2 -
2 files changed, 50 insertions(+), 18 deletions(-)
New commits:
commit d74b904a233a22c0ee81fd11f65d6d4b9319357a
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Tue May 17 23:17:10 2011 -0430
Fix index out of bounds in ScTableConditionalFormat.
Signed-off-by: Kohei Yoshida <kyoshida at novell.com>
diff --git a/sc/source/ui/unoobj/fmtuno.cxx b/sc/source/ui/unoobj/fmtuno.cxx
index e88369e..5c37c53 100644
--- a/sc/source/ui/unoobj/fmtuno.cxx
+++ b/sc/source/ui/unoobj/fmtuno.cxx
@@ -286,7 +286,7 @@ void ScTableConditionalFormat::AddEntry_Impl(const ScCondFormatEntryItem& aEntry
ScTableConditionalEntry* ScTableConditionalFormat::GetObjectByIndex_Impl(sal_uInt16 nIndex) const
{
- return aEntries[nIndex];
+ return nIndex < aEntries.size() ? aEntries[nIndex] : NULL;
}
void SAL_CALL ScTableConditionalFormat::addNew(
commit 7a249586c0fd056f7fc6919cdc3d1d51034f2425
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Tue May 17 11:33:17 2011 -0400
fdo#37226: Use real function objects with standard algorithms.
This fixes a crasher, and also some incorrect usage of standard
algorithms, where boolean values were passed which end up doing
things that the original author probably never intended.
diff --git a/sc/source/ui/docshell/autostyl.cxx b/sc/source/ui/docshell/autostyl.cxx
index d05676e..10773c4 100644
--- a/sc/source/ui/docshell/autostyl.cxx
+++ b/sc/source/ui/docshell/autostyl.cxx
@@ -64,6 +64,34 @@ inline sal_uLong TimeNow() // Sekunden
return (sal_uLong) time(0);
}
+namespace {
+
+class FindByRange : public ::std::unary_function<ScAutoStyleData, bool>
+{
+ ScRange maRange;
+public:
+ FindByRange(const ScRange& r) : maRange(r) {}
+ bool operator() (const ScAutoStyleData& rData) const { return rData.aRange == maRange; }
+};
+
+class FindByTimeout : public ::std::unary_function<ScAutoStyleData, bool>
+{
+ sal_uLong mnTimeout;
+public:
+ FindByTimeout(sal_uLong n) : mnTimeout(n) {}
+ bool operator() (const ScAutoStyleData& rData) const { return rData.nTimeout >= mnTimeout; }
+};
+
+struct FindNonZeroTimeout : public ::std::unary_function<ScAutoStyleData, bool>
+{
+ bool operator() (const ScAutoStyleData& rData) const
+ {
+ return rData.nTimeout != 0;
+ }
+};
+
+}
+
ScAutoStyleList::ScAutoStyleList(ScDocShell* pShell) :
pDocSh( pShell )
{
@@ -108,8 +136,12 @@ void ScAutoStyleList::AddEntry( sal_uLong nTimeout, const ScRange& rRange, const
aTimer.Stop();
sal_uLong nNow = TimeNow();
- aEntries.erase(std::remove_if(aEntries.begin(),aEntries.end(),
- boost::bind(&ScAutoStyleData::aRange,_1) == rRange));
+ // Remove the first item with the same range.
+ ::boost::ptr_vector<ScAutoStyleData>::iterator itr =
+ ::std::find_if(aEntries.begin(), aEntries.end(), FindByRange(rRange));
+
+ if (itr != aEntries.end())
+ aEntries.erase(itr);
// Timeouts von allen Eintraegen anpassen
@@ -120,8 +152,8 @@ void ScAutoStyleList::AddEntry( sal_uLong nTimeout, const ScRange& rRange, const
}
// Einfuege-Position suchen
- boost::ptr_vector<ScAutoStyleData>::iterator iter = std::find_if(aEntries.begin(),aEntries.end(),
- boost::bind(&ScAutoStyleData::nTimeout,_1) >= nTimeout);
+ boost::ptr_vector<ScAutoStyleData>::iterator iter =
+ ::std::find_if(aEntries.begin(), aEntries.end(), FindByTimeout(nTimeout));
aEntries.insert(iter,new ScAutoStyleData(nTimeout,rRange,rStyle));
@@ -145,19 +177,19 @@ void ScAutoStyleList::AdjustEntries( sal_uLong nDiff ) // Millisekunden
void ScAutoStyleList::ExecuteEntries()
{
- boost::ptr_vector<ScAutoStyleData>::iterator iter;
- for (iter = aEntries.begin(); iter != aEntries.end();)
+ // Execute and remove all items with timeout == 0 from the begin position
+ // until the first item with non-zero timeout value.
+ ::boost::ptr_vector<ScAutoStyleData>::iterator itr = aEntries.begin(), itrEnd = aEntries.end();
+ for (; itr != itrEnd; ++itr)
{
- if (!iter->nTimeout)
- {
- pDocSh->DoAutoStyle(iter->aRange,iter->aStyle);
- iter = aEntries.erase(iter);
- }
- else
- {
- ++iter;
- }
+ if (itr->nTimeout)
+ break;
+
+ pDocSh->DoAutoStyle(itr->aRange, itr->aStyle);
}
+ // At this point itr should be on the first item with non-zero timeout, or
+ // the end position in case all items have timeout == 0.
+ aEntries.erase(aEntries.begin(), itr);
}
void ScAutoStyleList::ExecuteAllNow()
@@ -174,8 +206,8 @@ void ScAutoStyleList::ExecuteAllNow()
void ScAutoStyleList::StartTimer( sal_uLong nNow ) // Sekunden
{
// ersten Eintrag mit Timeout != 0 suchen
- boost::ptr_vector<ScAutoStyleData>::iterator iter = std::find_if(aEntries.begin(),aEntries.end(),
- boost::bind(&ScAutoStyleData::nTimeout,_1) != static_cast<unsigned>(0));
+ boost::ptr_vector<ScAutoStyleData>::iterator iter =
+ ::std::find_if(aEntries.begin(),aEntries.end(), FindNonZeroTimeout());
if (iter != aEntries.end())
{
More information about the Libreoffice-commits
mailing list