diff options
-rw-r--r-- | amount.cc | 11 | ||||
-rw-r--r-- | balance.h | 29 | ||||
-rw-r--r-- | value.cc | 3 | ||||
-rw-r--r-- | walk.h | 3 |
4 files changed, 27 insertions, 19 deletions
@@ -276,11 +276,12 @@ amount_t& amount_t::operator=(const char * value) // assignment operator amount_t& amount_t::operator=(const amount_t& amt) { - if (amt.quantity) - _copy(amt); - else if (quantity) - _clear(); - + if (this != &amt) { + if (amt.quantity) + _copy(amt); + else if (quantity) + _clear(); + } return *this; } @@ -70,11 +70,13 @@ class balance_t // assignment operator balance_t& operator=(const balance_t& bal) { - amounts.clear(); - for (amounts_map::const_iterator i = bal.amounts.begin(); - i != bal.amounts.end(); - i++) - *this += (*i).second; + if (this != &bal) { + amounts.clear(); + for (amounts_map::const_iterator i = bal.amounts.begin(); + i != bal.amounts.end(); + i++) + *this += (*i).second; + } return *this; } balance_t& operator=(const amount_t& amt) { @@ -452,15 +454,16 @@ class balance_pair_t // assignment operator balance_pair_t& operator=(const balance_pair_t& bal_pair) { - if (cost) { - delete cost; - cost = NULL; + if (this != &bal_pair) { + if (cost) { + delete cost; + cost = NULL; + } + + quantity = bal_pair.quantity; + if (bal_pair.cost) + cost = new balance_t(*bal_pair.cost); } - - quantity = bal_pair.quantity; - if (bal_pair.cost) - cost = new balance_t(*bal_pair.cost); - return *this; } balance_pair_t& operator=(const balance_t& bal) { @@ -22,6 +22,9 @@ void value_t::destroy() value_t& value_t::operator=(const value_t& value) { + if (this == &value) + return *this; + destroy(); switch (value.type) { case BOOLEAN: @@ -53,8 +53,9 @@ class compare_items { assert(right); value_t left_result; - sort_order->compute(left_result, details_t(left)); value_t right_result; + + sort_order->compute(left_result, details_t(left)); sort_order->compute(right_result, details_t(right)); return left_result < right_result; |