From f079a626a03d4a6e7be1031ddb2e971c8b9a9a75 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 6 Apr 2016 07:43:51 +0200 Subject: Fix NULL variable value assignment bug --- build2/variable.cxx | 46 ++++++++++++++++++++++++++++------------------ 1 file 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 ()); + if (type == nullptr) + { + if (null ()) + new (&data_) names (move (v).as ()); + else + as () = move (v).as (); + } + else if (auto f = null () ? type->copy_ctor : type->copy_assign) + f (*this, v, true); else - as () = move (v).as (); + 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 ()); + if (type == nullptr) + { + if (null ()) + new (&data_) names (v.as ()); + else + as () = v.as (); + } + else if (auto f = null () ? type->copy_ctor : type->copy_assign) + f (*this, v, false); else - as () = v.as (); + 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; -- cgit v1.1