[libxml2] xmlNodeSetName: Allow setting the name to a substring of the currently set name
- From: Daniel Veillard <veillard src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] xmlNodeSetName: Allow setting the name to a substring of the currently set name
- Date: Wed, 23 Apr 2014 02:43:53 +0000 (UTC)
commit f0dd6e11aa56addced3de33fab30529a51efaed5
Author: Tristan Van Berkom <tristan upstairslabs com>
Date: Tue Apr 22 21:15:05 2014 -0400
xmlNodeSetName: Allow setting the name to a substring of the currently set name
Avoid freeing the currently set name until after having assigned the new name,
this allows one to call xmlNodeSetName (node, node->name + 1) to set the new
name of the node to a substring of the current name without introducing any
crash and without requiring an extra strdup().
tree.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/tree.c b/tree.c
index df6206d..7853e35 100644
--- a/tree.c
+++ b/tree.c
@@ -5096,6 +5096,7 @@ void
xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) {
xmlDocPtr doc;
xmlDictPtr dict;
+ const xmlChar *freeme = NULL;
if (cur == NULL) return;
if (name == NULL) return;
@@ -5133,12 +5134,16 @@ xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) {
dict = NULL;
if (dict != NULL) {
if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name)))
- xmlFree((xmlChar *) cur->name);
+ freeme = cur->name;
cur->name = xmlDictLookup(dict, name, -1);
} else {
- if (cur->name != NULL) xmlFree((xmlChar *) cur->name);
+ if (cur->name != NULL)
+ freeme = cur->name;
cur->name = xmlStrdup(name);
}
+
+ if (freeme)
+ xmlFree((xmlChar *) freeme);
}
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]