aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-04-06 07:43:51 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-04-06 07:43:51 +0200
commitf079a626a03d4a6e7be1031ddb2e971c8b9a9a75 (patch)
treedda61aaf2b1029178af2070b59c41556e76e41b7
parenta1ee4e9205497e44f211578aa8dd9e0758d19a0e (diff)
Fix NULL variable value assignment bug
-rw-r--r--build2/variable.cxx46
1 files changed, 28 insertions, 18 deletions
diff --git a/build2/variable.cxx b/build2/variable.cxx
index a8e3c77..da7446d 100644
--- a/build2/variable.cxx
+++ b/build2/variable.cxx
@@ -73,19 +73,24 @@ namespace build2
// Now our types are the same. If the receiving value is NULL, then call
// copy_ctor() instead of copy_assign().
//
- if (type == nullptr)
+ if (!v.null ())
{
- if (null ())
- new (&data_) names (move (v).as<names> ());
+ if (type == nullptr)
+ {
+ if (null ())
+ new (&data_) names (move (v).as<names> ());
+ else
+ as<names> () = move (v).as<names> ();
+ }
+ else if (auto f = null () ? type->copy_ctor : type->copy_assign)
+ f (*this, v, true);
else
- as<names> () = move (v).as<names> ();
+ data_ = v.data_; // Assign as POD.
+
+ state = v.state;
}
- else if (auto f = null () ? type->copy_ctor : type->copy_assign)
- f (*this, v, true);
else
- data_ = v.data_; // Assign as POD.
-
- state = v.state;
+ *this = nullptr;
}
return *this;
@@ -109,19 +114,24 @@ namespace build2
// Now our types are the same. If the receiving value is NULL, then call
// copy_ctor() instead of copy_assign().
//
- if (type == nullptr)
+ if (!v.null ())
{
- if (null ())
- new (&data_) names (v.as<names> ());
+ if (type == nullptr)
+ {
+ if (null ())
+ new (&data_) names (v.as<names> ());
+ else
+ as<names> () = v.as<names> ();
+ }
+ else if (auto f = null () ? type->copy_ctor : type->copy_assign)
+ f (*this, v, false);
else
- as<names> () = v.as<names> ();
+ data_ = v.data_; // Assign as POD.
+
+ state = v.state;
}
- else if (auto f = null () ? type->copy_ctor : type->copy_assign)
- f (*this, v, false);
else
- data_ = v.data_; // Assign as POD.
-
- state = v.state;
+ *this = nullptr;
}
return *this;