self-assignment bug in hsTArray

Announcements and discussion regarding any projects related to Cyan Worlds' Plasma Engine including (but not limited to) CyanWorlds.com Engine, Drizzle, OfflineKI, PyPRP, and libHSPlasma.

self-assignment bug in hsTArray

Postby Branan » Thu Feb 18, 2010 4:41 pm

The following code:
Code: Select all
hsTArray a;
a = a
will not work as expected. 'a' clears its data structures, then attempts to copy from itself, copying nothing. The correct method is to check for self-assignment. Patch:
Code: Select all
Index: core/Util/hsTArray.hpp
===================================================================
--- core/Util/hsTArray.hpp      (revision 359)
+++ core/Util/hsTArray.hpp      (working copy)
@@ -26,6 +26,8 @@
     }

     hsTArray<T>& operator=(const hsTArray& cpy) {
+        if (&cpy == this) return *this;
+
         clear();
         count = cpy.count;
         data = new T[count];
Image
Your friendly neighborhood shard admin
User avatar
Branan
Gehn Shard Admin
 
Posts: 694
Joined: Fri Nov 16, 2007 9:45 pm
Location: Portland, OR

Re: self-assignment bug in hsTArray

Postby Zrax » Thu Feb 18, 2010 6:40 pm

Hmm, dunno why anyone would do that, but thanks anyway for catching it ;)

EDIT: Applied fix to hsTList as well
User avatar
Zrax
 
Posts: 206
Joined: Fri Sep 28, 2007 5:19 pm
Location: Waist-deep in a conecano


Return to Plasma Development

Who is online

Users browsing this forum: No registered users and 20 guests