[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    kspread: patch for crash
From:       Ariya Hidayat <ariya () kde ! org>
Date:       2003-11-09 10:49:17
[Download RAW message or body]

The attached patch fixes bug 58713 (crash on opening file). The problem 
was simple, there were possibilities of undefined struct members, i.e in 
KSpreadConditional. For simplicity and safety, I also converted into a 
class with proper copy constructor and assignment operator.


Best regards,


Ariya Hidayat
http://ariya.pandu.org/blog

["cond.patch" (text/plain)]

--- kspread_condition.h.orig	2003-04-04 23:54:20.000000000 +0200
+++ kspread_condition.h	2003-11-09 10:41:43.000000000 +0100
@@ -38,8 +38,9 @@ class QString;
  * Structure to indicate the condition we're testing on a cell and the special
  * font and color that will be applied if it's true
  */
-struct KSpreadConditional
+class KSpreadConditional
 {
+public:
   double         val1;
   double         val2;
   QString *      strVal1;
@@ -49,6 +50,11 @@ struct KSpreadConditional
   QString *      styleName;
   KSpreadStyle * style;
   Conditional    cond;
+
+  KSpreadConditional();
+  ~KSpreadConditional();
+  KSpreadConditional( const KSpreadConditional& );
+  KSpreadConditional& operator=( const KSpreadConditional& );
 };
 

--- kspread_condition.cc.orig	2003-04-04 23:54:20.000000000 +0200
+++ kspread_condition.cc	2003-11-09 11:10:18.000000000 +0100
@@ -33,25 +33,51 @@
 
 #include <kdebug.h>
 
+KSpreadConditional::KSpreadConditional():
+  val1( 0.0 ), val2( 0.0 ), strVal1( 0 ), strVal2( 0 ),
+  colorcond( 0 ), fontcond( 0 ), styleName( 0 ),
+  style( 0 ), cond( None )
+{
+}
+
+KSpreadConditional::~KSpreadConditional()
+{
+  delete strVal1;
+  delete strVal2;
+  delete colorcond;
+  delete fontcond;
+  delete styleName;
+}
+
+KSpreadConditional::KSpreadConditional( const KSpreadConditional& c )
+{
+  operator=( c );
+}
+
+KSpreadConditional& KSpreadConditional::operator=( const KSpreadConditional& d )
+{
+  strVal1 = d.strVal1 ? new QString( *d.strVal1 ) : 0;
+  strVal2 = d.strVal2 ? new QString( *d.strVal2 ) : 0;
+  styleName = d.styleName ? new QString( *d.styleName ) : 0;
+  fontcond = d.fontcond ? new QFont( *d.fontcond ) : 0;
+  colorcond = d.colorcond ? new QColor( *d.colorcond ) : 0;
+  val1  = d.val1;
+  val2  = d.val2;
+  style = d.style;
+  cond  = d.cond;
+
+  return *this;
+}
+
 
 KSpreadConditions::KSpreadConditions( const KSpreadCell * ownerCell )
-  : m_cell( ownerCell )
+  : m_cell( ownerCell ), m_matchedStyle( 0 )
 {
   Q_ASSERT( ownerCell != NULL );
 }
 
 KSpreadConditions::~KSpreadConditions()
 {
-  QValueList<KSpreadConditional>::const_iterator it;
-  for ( it = m_condList.begin(); it != m_condList.end(); ++it )
-  {
-    KSpreadConditional c = *it;
-    delete c.strVal1;
-    delete c.strVal2;
-    delete c.fontcond;
-    delete c.colorcond;
-    delete c.styleName;
-  }
   m_condList.clear();
 }

@@ -194,39 +220,12 @@ QValueList<KSpreadConditional> KSpreadCo
 void KSpreadConditions::setConditionList( const QValueList<KSpreadConditional> & list )
 {
   m_condList.clear();
-  KSpreadConditional newCondition;
 
   QValueList<KSpreadConditional>::const_iterator it;
   for ( it = list.begin(); it != list.end(); ++it )
   {
     KSpreadConditional d = *it;
-    if ( d.strVal1 )
-      newCondition.strVal1 = new QString( *d.strVal1 );
-    else
-      newCondition.strVal1   = 0;
-    if ( d.strVal2 )
-      newCondition.strVal2 = new QString( *d.strVal2 );
-    else
-      newCondition.strVal2   = 0;
-    if ( d.styleName )
-      newCondition.styleName = new QString( *d.styleName );
-    else
-      newCondition.styleName = 0;
-    if ( d.fontcond )
-      newCondition.fontcond = new QFont( *d.fontcond );
-    else
-      newCondition.fontcond  = 0;
-    if ( d.colorcond )
-      newCondition.colorcond = new QColor( *d.colorcond );
-    else
-      newCondition.colorcond = 0;
-
-    newCondition.val1  = d.val1;
-    newCondition.val2  = d.val2;
-    newCondition.style = d.style;
-    newCondition.cond  = d.cond;
-
-    m_condList.append( newCondition );
+    m_condList.append( KSpreadConditional( d ) );
   }
 }

 


_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic