Self-assignment in PropertyBag::operator=

Hi,

I have discovered a self-assignment in the PropertyBag::operator=.

PropertyBag& PropertyBag::operator=(const PropertyBag& orig)
{
this->clear();

const_iterator i = orig.getProperties().begin();
while (i != orig.getProperties().end() )
{
add( (*i) );
++i;
}
this->setType( orig.getType() );
return *this;
}

This should be something like this:
PropertyBag& PropertyBag::operator=(const PropertyBag& orig)
{
if(this == &orig)
return *this;

this->clear();

const_iterator i = orig.getProperties().begin();
while (i != orig.getProperties().end() )
{
add( (*i) );
++i;
}
this->setType( orig.getType() );
return *this;
}

Self-assignment in PropertyBag::operator=

On Wed, Oct 7, 2009 at 13:47, Butch Slayer <butch [dot] slayers [..] ...> wrote:
> Hi,
>
> I have discovered a self-assignment in the PropertyBag::operator=.
>
> PropertyBag& PropertyBag::operator=(const PropertyBag& orig)
>     {
>         this->clear();
>
>         const_iterator i = orig.getProperties().begin();
>         while (i != orig.getProperties().end() )
>             {
>                 add( (*i) );
>                 ++i;
>             }
>         this->setType( orig.getType() );
>         return *this;
>     }
>
> This should be something like this:
> PropertyBag& PropertyBag::operator=(const PropertyBag& orig)
>     {
>         if(this == &orig)
>             return *this;
>
>         this->clear();
>
>         const_iterator i = orig.getProperties().begin();
>         while (i != orig.getProperties().end() )
>             {
>                 add( (*i) );
>                 ++i;
>             }
>         this->setType( orig.getType() );
>         return *this;
>     }
>

Yep. Major bug ! Thanks for reporting.

Peter