[Kst] kdeextragear-2/kst/kst

George Staikos staikos at kde.org
Wed Jan 12 04:49:47 CET 2005


CVS commit by staikos: 

fix memory error (crash) introduced with new plot cleanup algorithm.  Discovered
by regression tests.


  M +10 -14    kstviewobject.cpp   1.113


--- kdeextragear-2/kst/kst/kstviewobject.cpp  #1.112:1.113
@@ -506,6 +506,4 @@ void KstViewObject::cleanup(int cols) {
   }
 
-  KstViewObjectList childrenCopy;
-  double distance;
   double minDistance = 0.0;
   int pos = 0;
@@ -516,5 +514,5 @@ void KstViewObject::cleanup(int cols) {
   int h = _geom.height() / (lastRow + (_children.count() % _columns > 0 ? 1 : 0));
 
-  childrenCopy = QDeepCopy<KstViewObjectList>(_children);
+  KstViewObjectList childrenCopy = QDeepCopy<KstViewObjectList>(_children);
 
   //kdDebug() << "cleanup with w=" << w << " and h=" << h << endl;
@@ -537,7 +535,6 @@ void KstViewObject::cleanup(int cols) {
     for (KstViewObjectList::Iterator it = childrenCopy.begin(); it != childrenCopy.end(); ++it) {
       // find plot closest to the desired position, based on top-left corner...
-      distance  = (double)(( x - (*it)->geometry().x() ) * ( x - (*it)->geometry().x() ));
-      distance += (double)(( y - (*it)->geometry().y() ) * ( y - (*it)->geometry().y() ));
-      if( it == childrenCopy.begin() || distance < minDistance ) {
+      double distance = double((x - (*it)->geometry().x()) * (x - (*it)->geometry().x())) + double((y - (*it)->geometry().y()) * (y - (*it)->geometry().y()));
+      if (it == childrenCopy.begin() || distance < minDistance) {
         minDistance = distance;
         nearest = it;
@@ -544,8 +541,10 @@ void KstViewObject::cleanup(int cols) {
       }
     }
+
     if (nearest != childrenCopy.end()) {
-      (*nearest)->move(pt);
-      (*nearest)->resize(sz);
-      childrenCopy.remove(*nearest);
+      KstViewObjectPtr vop = *nearest;
+      vop->move(pt);
+      vop->resize(sz);
+      childrenCopy.remove(vop);
     }
 
@@ -576,5 +575,5 @@ void KstViewObject::move(const QPoint& p
   QPoint offset = pos - _geom.topLeft();
 
-  if( !offset.isNull() ) {
+  if (!offset.isNull()) {
     _geom.moveTopLeft(pos);
     updateAspectPos( );
@@ -1205,8 +1204,5 @@ void KstViewObject::unselectAll() {
 bool KstViewObject::contains(KstViewObjectPtr child) {
   for (KstViewObjectList::Iterator i = _children.begin(); i != _children.end(); ++i) {
-    if ((*i).data() == child.data()) {
-      return true;
-    }
-    if ((*i)->contains(child)) {
+    if ((*i).data() == child.data() || (*i)->contains(child)) {
       return true;
     }




More information about the Kst mailing list