From: Remi Gacogne Date: Mon, 21 May 2018 16:23:00 +0000 (+0200) Subject: Don't copy unitialized values of SuffixMatchTree X-Git-Tag: dnsdist-1.3.1~72^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F6637%2Fhead;p=thirdparty%2Fpdns.git Don't copy unitialized values of SuffixMatchTree --- diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 7e0419f314..f2d9eee21c 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -233,8 +233,11 @@ struct SuffixMatchTree SuffixMatchTree(const std::string& name="", bool endNode_=false) : d_name(name), endNode(endNode_) {} - SuffixMatchTree(const SuffixMatchTree& rhs): d_name(rhs.d_name), children(rhs.children), endNode(rhs.endNode), d_value(rhs.d_value) + SuffixMatchTree(const SuffixMatchTree& rhs): d_name(rhs.d_name), children(rhs.children), endNode(rhs.endNode) { + if (endNode) { + d_value = rhs.d_value; + } } std::string d_name; mutable std::set children; @@ -266,8 +269,7 @@ struct SuffixMatchTree d_value=value; } else if(labels.size()==1) { - SuffixMatchTree newChild(*labels.begin(), true); - auto res=children.insert(newChild); + auto res=children.emplace(*labels.begin(), true); if(!res.second) { // we might already have had the node as an // intermediary one, but it's now an end node @@ -278,8 +280,7 @@ struct SuffixMatchTree res.first->d_value = value; } else { - SuffixMatchTree newnode(*labels.rbegin(), false); - auto res=children.insert(newnode); + auto res=children.emplace(*labels.rbegin(), false); labels.pop_back(); res.first->add(labels, value); }