]> granicus.if.org Git - pdns/commitdiff
Don't copy unitialized values of SuffixMatchTree
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 21 May 2018 16:23:00 +0000 (18:23 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 21 May 2018 16:23:00 +0000 (18:23 +0200)
pdns/dnsname.hh

index 7e0419f3142cad16edf0e0371a482f010bb1d5a0..f2d9eee21c196b3ff12a42d86fa6d0176a924bf9 100644 (file)
@@ -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<SuffixMatchTree> 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);
     }