_set_value bug (and a patch)

Nikolai Kondrashov <[email protected]>
Newsgroups gmane.text.clearsilver.general
Message-ID <[email protected]>
Hello, everyone!

It seems I have found a bug in the _set_value function, and again, related
to symlinks (yes, I know symlink usage isn't recommended, but nevertheless).

If you try to set the value of some non-existing sub-node of the node which
is a link, the interstitial nodes are created below this node and not below
the node to which the link points, as one would expect.

Say, if you have following dataset:

a : b
b {
  c {
  }
}


And try to call hdf_get_node(hdf, "a.c.d", &node) you will get following result:

a : b
a {
  c {
    d {
    }
  }
b {
  c {
  }
}

Instead of the obvious:

a : b
b {
  c {
    d {
    }
  }
}

But if the "b.c.d" existed the hdf_get_node would work correctly.

I have attached a quick and dirty patch which seems to work, and also
includes a small fix (which seems logical to me) for proper handling of the
links in the interstitial nodes in case the hdf parameter is not the top node.

Thank you for your attention :)

Sincerely,
Nick
_set_value.patch (text/x-patch, 1000 B)
--- util/neo_hdf.c	(revision 40079)
+++ util/neo_hdf.c	(working copy)
@@ -640,7 +640,24 @@
     return nerr_raise(NERR_ASSERT, "Unable to set Empty component %s", name);
   }
 
-  hn = hdf;
+  if (hdf->link)
+  {
+    char *new_name = (char *) malloc(strlen(hdf->value) + 1 + strlen(name) + 1);
+    if (new_name == NULL)
+    {
+      return nerr_raise(NERR_NOMEM, "Unable to allocate memory");
+    }
+    strcpy(new_name, hdf->value);
+    strcat(new_name, ".");
+    strcat(new_name, name);
+    err = _set_value (hdf->top, new_name, value, dup, wf, link, attr, set_node);
+    free(new_name);
+    return nerr_pass(err);
+  }
+  else
+  {
+    hn = hdf;
+  }
 
   while (1)
   {
@@ -779,7 +796,7 @@
       }
       strcpy(new_name, hp->value);
       strcat(new_name, s);
-      err = _set_value (hdf, new_name, value, dup, wf, link, attr, set_node);
+      err = _set_value (hdf->top, new_name, value, dup, wf, link, attr, set_node);
       free(new_name);
       return nerr_pass(err);
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.