Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


On 17/05/11 17:04, Kohei Yoshida wrote:
Hi there,

The attached patch fixes the crasher reported in the following bug:

https://bugs.freedesktop.org/show_bug.cgi?id=37226

and also several other usage of standard algorithms which I believe is
incorrect, since the existing code passes the result of an evaluation
which is always boolean (unless boost::bind overloads those operators to
return something else, which I doubt it does).
I don't know much about boost, have seen the bind stuff peppered here and there in the code and generally liked the look of it, anyway your question prompted me to try and understand more, the following link http://www.boost.org/doc/libs/1_46_1/libs/bind/bind.html#operators seems to indicate that it is the operator is passed to the standard algorithm and not the result ( but maybe I misunderstood, this stuff is still unfamiliar to me )
   There were several cases
where such evaluation result was passed to standard algorithms, one of
which caused the crash.
I tried your patch ( but with the bind bits left in ) and it seemed to work find for me ( especially wrt to the operator stuff above ) attached is the patch I used

Noel
diff --git a/sc/source/ui/docshell/autostyl.cxx b/sc/source/ui/docshell/autostyl.cxx
index d05676e..d1fa26f 100644
--- a/sc/source/ui/docshell/autostyl.cxx
+++ b/sc/source/ui/docshell/autostyl.cxx
@@ -108,8 +108,10 @@ 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));
+    ::boost::ptr_vector<ScAutoStyleData>::iterator itr = 
std::find_if(aEntries.begin(),aEntries.end(), boost::bind(&ScAutoStyleData::aRange,_1) == rRange);
+
+    if (itr != aEntries.end())
+        aEntries.erase(itr);
 
     // Timeouts von allen Eintraegen anpassen
 
@@ -145,19 +147,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()

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.