Jelajahi Sumber

Merge pull request #9732 from jakesmith/hpcc-17249

HPCC-17249 Various small ptree fixes

Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Gavin Halliday 8 tahun lalu
induk
melakukan
60effe6d26
1 mengubah file dengan 8 tambahan dan 3 penghapusan
  1. 8 3
      system/jlib/jptree.cpp

+ 8 - 3
system/jlib/jptree.cpp

@@ -1474,7 +1474,13 @@ IPropertyTree *PTree::addPropTree(const char *xpath, IPropertyTree *val)
                 IPropertyTree *_val = ownPTree(val);
                 IPropertyTree *_val = ownPTree(val);
                 dbgassertex(QUERYINTERFACE(_val, PTree));
                 dbgassertex(QUERYINTERFACE(_val, PTree));
                 PTree *__val = static_cast<PTree *>(_val);
                 PTree *__val = static_cast<PTree *>(_val);
+
+                /* NB: potentially param xpath is a reference to the existing name.
+                 * So fetch new name ptr after set.
+                 */
                 __val->setName(xpath);
                 __val->setName(xpath);
+                xpath = __val->queryName();
+
                 addingNewElement(*_val, -1);
                 addingNewElement(*_val, -1);
                 if (checkChildren())
                 if (checkChildren())
                 {
                 {
@@ -1656,7 +1662,7 @@ bool PTree::removeProp(const char *xpath)
                     {
                     {
                         StringAttr digit(digitStart, xxpath-digitStart);
                         StringAttr digit(digitStart, xxpath-digitStart);
                         unsigned i = atoi(digit);
                         unsigned i = atoi(digit);
-                        if (i <= child->value->elements())
+                        if (i && i <= child->value->elements())
                         {
                         {
                             removingElement(child->value->queryElement(i-1), i-1);
                             removingElement(child->value->queryElement(i-1), i-1);
                             child->value->removeElement(i-1);
                             child->value->removeElement(i-1);
@@ -2363,8 +2369,7 @@ void PTree::clone(IPropertyTree &srcTree, IPropertyTree &dstTree, bool sub)
             {
             {
                 IPropertyTree &child = iter->query();
                 IPropertyTree &child = iter->query();
                 IPropertyTree *newChild = clone(child, false, sub);
                 IPropertyTree *newChild = clone(child, false, sub);
-                StringAttr name(newChild->queryName());
-                dstTree.addPropTree(name, newChild);
+                dstTree.addPropTree(newChild->queryName(), newChild);
             }
             }
             while (iter->next());
             while (iter->next());
         }
         }