]> git.saurik.com Git - wxWidgets.git/commitdiff
check for self-assignment in operator=
authorPaul Cornett <paulcor@bullseye.com>
Wed, 9 Jan 2008 04:08:33 +0000 (04:08 +0000)
committerPaul Cornett <paulcor@bullseye.com>
Wed, 9 Jan 2008 04:08:33 +0000 (04:08 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51123 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

12 files changed:
include/wx/accel.h
include/wx/buffer.h
include/wx/cmndata.h
include/wx/dynarray.h
include/wx/event.h
include/wx/gtk/dataform.h
include/wx/hashmap.h
include/wx/list.h
include/wx/string.h
include/wx/unichar.h
include/wx/utils.h
include/wx/windowid.h

index 025b51b375f5013a805be2def8b4da5dbad6cd8a..ee2e3a08ad5817f4a1d8bf0cde92183a1038de97 100644 (file)
@@ -68,7 +68,8 @@ public:
 
     wxAcceleratorEntry& operator=(const wxAcceleratorEntry& entry)
     {
 
     wxAcceleratorEntry& operator=(const wxAcceleratorEntry& entry)
     {
-        Set(entry.m_flags, entry.m_keyCode, entry.m_command, entry.m_item);
+        if (&entry != this)
+            Set(entry.m_flags, entry.m_keyCode, entry.m_command, entry.m_item);
         return *this;
     }
 
         return *this;
     }
 
index 81a445afe57bbc98a9c03039efdc37075691eeeb..d06fbf6fc15b57a76d726521cd9f4295621bd111 100644 (file)
@@ -105,9 +105,12 @@ public:
 
     wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src)
     {
 
     wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src)
     {
-        if ( m_owned )
-            free(m_str);
-        CopyFrom(src);
+        if (&src != this)
+        {
+            if ( m_owned )
+                free(m_str);
+            CopyFrom(src);
+        }
         return *this;
     }
 
         return *this;
     }
 
@@ -317,9 +320,12 @@ public:
 
     wxMemoryBuffer& operator=(const wxMemoryBuffer& src)
     {
 
     wxMemoryBuffer& operator=(const wxMemoryBuffer& src)
     {
-        m_bufdata->DecRef();
-        m_bufdata = src.m_bufdata;
-        m_bufdata->IncRef();
+        if (&src != this)
+        {
+            m_bufdata->DecRef();
+            m_bufdata = src.m_bufdata;
+            m_bufdata->IncRef();
+        }
         return *this;
     }
 
         return *this;
     }
 
index 0bfced12f30240f9d264b63315c0a2e8a16b5126..630415f4c359b166405906d506265c0abb003dee 100644 (file)
@@ -87,17 +87,20 @@ public:
 
     wxFontData& operator=(const wxFontData& data)
     {
 
     wxFontData& operator=(const wxFontData& data)
     {
-        wxObject::operator=(data);
-        m_fontColour     = data.m_fontColour;
-        m_showHelp       = data.m_showHelp;
-        m_allowSymbols   = data.m_allowSymbols;
-        m_enableEffects  = data.m_enableEffects;
-        m_initialFont    = data.m_initialFont;
-        m_chosenFont     = data.m_chosenFont;
-        m_minSize        = data.m_minSize;
-        m_maxSize        = data.m_maxSize;
-        m_encoding       = data.m_encoding;
-        m_encodingInfo   = data.m_encodingInfo;
+        if (&data != this)
+        {
+            wxObject::operator=(data);
+            m_fontColour     = data.m_fontColour;
+            m_showHelp       = data.m_showHelp;
+            m_allowSymbols   = data.m_allowSymbols;
+            m_enableEffects  = data.m_enableEffects;
+            m_initialFont    = data.m_initialFont;
+            m_chosenFont     = data.m_chosenFont;
+            m_minSize        = data.m_minSize;
+            m_maxSize        = data.m_maxSize;
+            m_encoding       = data.m_encoding;
+            m_encodingInfo   = data.m_encodingInfo;
+        }
         return *this;
     }
 
         return *this;
     }
 
index 9bdd300ee7f42594da3704fdbec5a3cc60e87fba..6dabfa5b2b87f64fc8842f9cbc4cb8fe5376686a 100644 (file)
@@ -334,11 +334,6 @@ public:                                                               \
   name() { }                                                          \
   ~name() { }                                                         \
                                                                       \
   name() { }                                                          \
   ~name() { }                                                         \
                                                                       \
-  name& operator=(const name& src)                                    \
-    { base* temp = (base*) this;                                      \
-      (*temp) = ((const base&)src);                                   \
-      return *this; }                                                 \
-                                                                      \
   T& operator[](size_t uiIndex) const                                 \
     { return (T&)(base::operator[](uiIndex)); }                       \
   T& Item(size_t uiIndex) const                                       \
   T& operator[](size_t uiIndex) const                                 \
     { return (T&)(base::operator[](uiIndex)); }                       \
   T& Item(size_t uiIndex) const                                       \
index 7b41f1ff387f499c51be84cb73761c4817fb0972..3e5bc79873e99f20c7c1dac7a5f6d92372b64e61 100644 (file)
@@ -778,7 +778,7 @@ public:
 
     virtual wxEvent *Clone() const { return new wxMouseEvent(*this); }
 
 
     virtual wxEvent *Clone() const { return new wxMouseEvent(*this); }
 
-    wxMouseEvent& operator=(const wxMouseEvent& event) { Assign(event); return *this; }
+    wxMouseEvent& operator=(const wxMouseEvent& event) { if (&event != this) Assign(event); return *this; }
 
 public:
     wxCoord m_x, m_y;
 
 public:
     wxCoord m_x, m_y;
@@ -940,22 +940,24 @@ public:
     // example)
     wxKeyEvent& operator=(const wxKeyEvent& evt)
     {
     // example)
     wxKeyEvent& operator=(const wxKeyEvent& evt)
     {
-        m_x = evt.m_x;
-        m_y = evt.m_y;
-
-        m_keyCode = evt.m_keyCode;
-
-        m_controlDown = evt.m_controlDown;
-        m_shiftDown = evt.m_shiftDown;
-        m_altDown = evt.m_altDown;
-        m_metaDown = evt.m_metaDown;
-        m_scanCode = evt.m_scanCode;
-        m_rawCode = evt.m_rawCode;
-        m_rawFlags = evt.m_rawFlags;
+        if (&evt != this)
+        {
+            m_x = evt.m_x;
+            m_y = evt.m_y;
+
+            m_keyCode = evt.m_keyCode;
+
+            m_controlDown = evt.m_controlDown;
+            m_shiftDown = evt.m_shiftDown;
+            m_altDown = evt.m_altDown;
+            m_metaDown = evt.m_metaDown;
+            m_scanCode = evt.m_scanCode;
+            m_rawCode = evt.m_rawCode;
+            m_rawFlags = evt.m_rawFlags;
 #if wxUSE_UNICODE
 #if wxUSE_UNICODE
-        m_uniChar = evt.m_uniChar;
+            m_uniChar = evt.m_uniChar;
 #endif
 #endif
-
+        }
         return *this;
     }
 
         return *this;
     }
 
@@ -2284,7 +2286,7 @@ protected:
     
 private:
     // It makes no sense to copy objects of this class 
     
 private:
     // It makes no sense to copy objects of this class 
-    wxEventConnectionRef& operator = (const wxEventConnectionRef& WXUNUSED(other)) { wxASSERT(0); return *this; } 
+    wxEventConnectionRef& operator = (const wxEventConnectionRef& WXUNUSED(other)) { wxFAIL; return *this; } 
 };
 
 
 };
 
 
index 1fc8372227b8beee615eaa89c1858d4ae44eecfa..86e0cd783804eb16b4c6d63e5e597e2d6dbaa64a 100644 (file)
@@ -30,7 +30,14 @@ public:
     wxDataFormat( const wxCStrData& id ) { InitFromString(id); }
 
     wxDataFormat& operator=(const wxDataFormat& format)
     wxDataFormat( const wxCStrData& id ) { InitFromString(id); }
 
     wxDataFormat& operator=(const wxDataFormat& format)
-        { m_type = format.m_type; m_format = format.m_format; return *this; }
+    {
+        if (&format != this)
+        {
+            m_type = format.m_type;
+            m_format = format.m_format;
+        }
+        return *this;
+    }
     wxDataFormat& operator=(NativeFormat format)
         { SetId(format); return *this; }
 
     wxDataFormat& operator=(NativeFormat format)
         { SetId(format); return *this; }
 
index 47d583b840b84de620cb42ef911f38d0dee8c393..836c2e3e54d5915935549232bc58761f63d9e501 100644 (file)
@@ -161,7 +161,7 @@ public: \
  \
         Iterator() : m_node(0), m_ht(0) {} \
         Iterator( Node* node, const Self* ht ) \
  \
         Iterator() : m_node(0), m_ht(0) {} \
         Iterator( Node* node, const Self* ht ) \
-            : m_node(node), m_ht((Self*)ht) {} \
+            : m_node(node), m_ht(wx_const_cast(Self*, ht)) {} \
         bool operator ==( const Iterator& it ) const \
             { return m_node == it.m_node; } \
         bool operator !=( const Iterator& it ) const \
         bool operator ==( const Iterator& it ) const \
             { return m_node == it.m_node; } \
         bool operator !=( const Iterator& it ) const \
@@ -204,7 +204,7 @@ public: \
         const_iterator() : Iterator() {} \
         const_iterator(iterator i) : Iterator(i) {} \
         const_iterator( Node* node, const Self* ht ) \
         const_iterator() : Iterator() {} \
         const_iterator(iterator i) : Iterator(i) {} \
         const_iterator( Node* node, const Self* ht ) \
-            : Iterator( node, (Self*)ht ) {} \
+            : Iterator(node, wx_const_cast(Self*, ht)) {} \
         const_iterator& operator++() { PlusPlus();return *this; } \
         const_iterator operator++(int) { const_iterator it=*this;PlusPlus();return it; } \
         const_reference operator *() const { return m_node->m_value; } \
         const_iterator& operator++() { PlusPlus();return *this; } \
         const_iterator operator++(int) { const_iterator it=*this;PlusPlus();return it; } \
         const_reference operator *() const { return m_node->m_value; } \
@@ -236,12 +236,15 @@ public: \
  \
     const Self& operator=( const Self& ht ) \
     { \
  \
     const Self& operator=( const Self& ht ) \
     { \
-         clear(); \
-         m_hasher = ht.m_hasher; \
-         m_equals = ht.m_equals; \
-         m_getKey = ht.m_getKey; \
-         m_items = ht.m_items; \
-         HashCopy( ht ); \
+         if (&ht != this) \
+         { \
+             clear(); \
+             m_hasher = ht.m_hasher; \
+             m_equals = ht.m_equals; \
+             m_getKey = ht.m_getKey; \
+             m_items = ht.m_items; \
+             HashCopy( ht ); \
+         } \
          return *this; \
     } \
  \
          return *this; \
     } \
  \
@@ -407,7 +410,8 @@ public: \
     typedef const KEY_T const_t1; \
     typedef const VALUE_T const_t2; \
  \
     typedef const KEY_T const_t1; \
     typedef const VALUE_T const_t2; \
  \
-    CLASSNAME( const const_t1& f, const const_t2& s ):first(t1(f)),second(t2(s)) {} \
+    CLASSNAME(const const_t1& f, const const_t2& s) \
+        : first(wx_const_cast(t1&, f)), second(wx_const_cast(t2&, s)) {} \
  \
     t1 first; \
     t2 second; \
  \
     t1 first; \
     t2 second; \
index c83ac08be3f6700a14dacdae66cdcaf6f8bf58f9..3aace939b46338426c6f934fd8b0860da4b106f3 100644 (file)
@@ -22,8 +22,8 @@
   like the old class.
 */
 
   like the old class.
 */
 
-#ifndef _WX_LISTH__
-#define _WX_LISTH__
+#ifndef _WX_LIST_H_
+#define _WX_LIST_H_
 
 // -----------------------------------------------------------------------------
 // headers
 
 // -----------------------------------------------------------------------------
 // headers
@@ -469,7 +469,7 @@ protected:
     virtual void DeleteData() { }
 public:
     // for wxList::iterator
     virtual void DeleteData() { }
 public:
     // for wxList::iterator
-    void** GetDataPtr() const { return &(((wxNodeBase*)this)->m_data); }
+    void** GetDataPtr() const { return &(wx_const_cast(wxNodeBase*, this)->m_data); }
 private:
     // optional key stuff
     wxListKeyValue m_key;
 private:
     // optional key stuff
     wxListKeyValue m_key;
@@ -732,7 +732,7 @@ private:
             : wxListBase(count, (void **)elements) { }                      \
                                                                             \
         name& operator=(const name& list)                                   \
             : wxListBase(count, (void **)elements) { }                      \
                                                                             \
         name& operator=(const name& list)                                   \
-            { Assign(list); return *this; }                                 \
+            { if (&list != this) Assign(list); return *this; }              \
                                                                             \
         nodetype *GetFirst() const                                          \
             { return (nodetype *)wxListBase::GetFirst(); }                  \
                                                                             \
         nodetype *GetFirst() const                                          \
             { return (nodetype *)wxListBase::GetFirst(); }                  \
@@ -1178,7 +1178,7 @@ public:
 
 #if !wxUSE_STL
     wxList& operator=(const wxList& list)
 
 #if !wxUSE_STL
     wxList& operator=(const wxList& list)
-        { Assign(list); return *this; }
+        { if (&list != this) Assign(list); return *this; }
 
     // compatibility methods
     void Sort(wxSortCompareFunction compfunc) { wxListBase::Sort(compfunc); }
 
     // compatibility methods
     void Sort(wxSortCompareFunction compfunc) { wxListBase::Sort(compfunc); }
@@ -1214,7 +1214,14 @@ public:
         // inefficient!)
     wxStringList(const wxStringList& other) : wxStringListBase() { DeleteContents(true); DoCopy(other); }
     wxStringList& operator=(const wxStringList& other)
         // inefficient!)
     wxStringList(const wxStringList& other) : wxStringListBase() { DeleteContents(true); DoCopy(other); }
     wxStringList& operator=(const wxStringList& other)
-        { Clear(); DoCopy(other); return *this; }
+    {
+        if (&other != this)
+        {
+            Clear();
+            DoCopy(other);
+        }
+        return *this;
+    }
 
     // operations
         // makes a copy of the string
 
     // operations
         // makes a copy of the string
index 2e7b6ca1b671ca5655cd3aabba2ffff00f17c6ec..2d7d3e3a9c21c8dcabb23429952a0a1fc0c14341 100644 (file)
@@ -657,7 +657,14 @@ public:
       iterator(const iterator& i)
           : m_cur(i.m_cur), m_node(i.str(), &m_cur) {}
       iterator& operator=(const iterator& i)
       iterator(const iterator& i)
           : m_cur(i.m_cur), m_node(i.str(), &m_cur) {}
       iterator& operator=(const iterator& i)
-        { m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; }
+      {
+          if (&i != this)
+          {
+              m_cur = i.m_cur;
+              m_node.set(i.str(), &m_cur);
+          }
+          return *this;
+      }
 
       reference operator*()
         { return wxUniCharRef::CreateForString(m_node, m_cur); }
 
       reference operator*()
         { return wxUniCharRef::CreateForString(m_node, m_cur); }
@@ -692,7 +699,14 @@ public:
           : m_cur(i.m_cur), m_node(i.str(), &m_cur) {}
 
       const_iterator& operator=(const const_iterator& i)
           : m_cur(i.m_cur), m_node(i.str(), &m_cur) {}
 
       const_iterator& operator=(const const_iterator& i)
-        { m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; }
+      {
+          if (&i != this)
+          {
+              m_cur = i.m_cur;
+              m_node.set(i.str(), &m_cur);
+          }
+          return *this;
+      }
       const_iterator& operator=(const iterator& i)
         { m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; }
 
       const_iterator& operator=(const iterator& i)
         { m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; }
 
@@ -1324,7 +1338,7 @@ public:
   // overloaded assignment
     // from another wxString
   wxString& operator=(const wxString& stringSrc)
   // overloaded assignment
     // from another wxString
   wxString& operator=(const wxString& stringSrc)
-    { m_impl = stringSrc.m_impl; return *this; }
+    { if (&stringSrc != this) m_impl = stringSrc.m_impl; return *this; }
   wxString& operator=(const wxCStrData& cstr)
     { return *this = cstr.AsString(); }
     // from a character
   wxString& operator=(const wxCStrData& cstr)
     { return *this = cstr.AsString(); }
     // from a character
index e2232d2817e1f8bc1ff620b56c5d31afd474727e..defc237114679e57013165dc85fb0278dda39f45 100644 (file)
@@ -96,7 +96,7 @@ public:
     bool operator&&(bool v) const { return (bool)*this && v; }
 
     // Assignment operators:
     bool operator&&(bool v) const { return (bool)*this && v; }
 
     // Assignment operators:
-    wxUniChar& operator=(const wxUniChar& c) { m_value = c.m_value; return *this; }
+    wxUniChar& operator=(const wxUniChar& c) { if (&c != this) m_value = c.m_value; return *this; }
     wxUniChar& operator=(const wxUniCharRef& c);
     wxUniChar& operator=(char c) { m_value = From8bit(c); return *this; }
     wxUniChar& operator=(unsigned char c) { m_value = From8bit((char)c); return *this; }
     wxUniChar& operator=(const wxUniCharRef& c);
     wxUniChar& operator=(char c) { m_value = From8bit(c); return *this; }
     wxUniChar& operator=(unsigned char c) { m_value = From8bit((char)c); return *this; }
@@ -218,7 +218,7 @@ public:
 #endif
 
     wxUniCharRef& operator=(const wxUniCharRef& c)
 #endif
 
     wxUniCharRef& operator=(const wxUniCharRef& c)
-        { return *this = c.UniChar(); }
+        { if (&c != this) *this = c.UniChar(); return *this; }
 
     wxUniCharRef& operator=(char c) { return *this = wxUniChar(c); }
     wxUniCharRef& operator=(unsigned char c) { return *this = wxUniChar(c); }
 
     wxUniCharRef& operator=(char c) { return *this = wxUniChar(c); }
     wxUniCharRef& operator=(unsigned char c) { return *this = wxUniChar(c); }
index 0baa6099d60e268c134bcb1d3f64ee93cb7e9c79..c7ea286b9dc316177a95838bfca15eeb9c2a6a61 100644 (file)
@@ -9,8 +9,8 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifndef _WX_UTILSH__
-#define _WX_UTILSH__
+#ifndef _WX_UTILS_H_
+#define _WX_UTILS_H_
 
 // ----------------------------------------------------------------------------
 // headers
 
 // ----------------------------------------------------------------------------
 // headers
@@ -136,7 +136,7 @@ class WXDLLIMPEXP_BASE wxPlatform
 public:
     wxPlatform() { Init(); }
     wxPlatform(const wxPlatform& platform) { Copy(platform); }
 public:
     wxPlatform() { Init(); }
     wxPlatform(const wxPlatform& platform) { Copy(platform); }
-    void operator = (const wxPlatform& platform) { Copy(platform); }
+    void operator = (const wxPlatform& platform) { if (&platform != this) Copy(platform); }
     void Copy(const wxPlatform& platform);
 
     // Specify an optional default value
     void Copy(const wxPlatform& platform);
 
     // Specify an optional default value
index 4b2e3e171c42b5ea8ddac2e92ca361fd4e8fdde4..e16b4534abe50f7cc078d502e0ac523974ef2b88 100644 (file)
@@ -72,7 +72,8 @@ public:
 
     wxWindowIDRef& operator=(const wxWindowIDRef& id)
     {
 
     wxWindowIDRef& operator=(const wxWindowIDRef& id)
     {
-        Assign(id.m_id);
+        if (&id != this)
+            Assign(id.m_id);
         return *this;
     }
 
         return *this;
     }