summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--amount.cc11
-rw-r--r--balance.h29
-rw-r--r--value.cc3
-rw-r--r--walk.h3
4 files changed, 27 insertions, 19 deletions
diff --git a/amount.cc b/amount.cc
index b72f9852..e0507c7c 100644
--- a/amount.cc
+++ b/amount.cc
@@ -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;
}
diff --git a/balance.h b/balance.h
index 7f547e8d..f88f3114 100644
--- a/balance.h
+++ b/balance.h
@@ -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) {
diff --git a/value.cc b/value.cc
index bf235257..83307dc0 100644
--- a/value.cc
+++ b/value.cc
@@ -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:
diff --git a/walk.h b/walk.h
index 238fdb78..39bde7f2 100644
--- a/walk.h
+++ b/walk.h
@@ -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;