From 63fa74b229dd25b1e6398f20b966725df855dcf3 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Tue, 20 Apr 2010 12:08:04 +0200 Subject: Allow format strings to be NULL in dmixml_Add*() functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This bug was reported by Jan Hutaƙ [1] The implemented fix avoids assertions if the format strings to dmixml_AddAttribute(), dmixml_AddTextChild() and dmixml_AddTextContent() functions are NULL. In these cases, it will result in an empty value instead of returning NULL from these functions. [1] --- src/dmixml.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/dmixml.c') diff --git a/src/dmixml.c b/src/dmixml.c index ba285e8..3b05ad4 100644 --- a/src/dmixml.c +++ b/src/dmixml.c @@ -92,13 +92,18 @@ xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt xmlAttr *res = NULL; va_list ap; - if( (node == NULL) || (atrname == NULL) || (fmt == NULL) ) { + if( (node == NULL) || (atrname == NULL) ) { return NULL; } atrname_s = xmlCharStrdup(atrname); assert( atrname_s != NULL ); + if( fmt == NULL ) { + res = xmlNewProp(node, atrname_s, NULL); + goto exit; + } + va_start(ap, fmt); val_s = dmixml_buildstr(2048, fmt, ap); va_end(ap); @@ -106,8 +111,9 @@ xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt res = xmlNewProp(node, atrname_s, (xmlStrcmp(val_s, (xmlChar *) "(null)") == 0 ? NULL : val_s)); - free(atrname_s); free(val_s); + exit: + free(atrname_s); assert( res != NULL ); return res; @@ -129,13 +135,18 @@ xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt xmlNode *res = NULL; va_list ap; - if( (node == NULL) || (tagname == NULL) || (fmt == NULL) ) { + if( (node == NULL) || (tagname == NULL) ) { return NULL; } tagname_s = xmlCharStrdup(tagname); assert( tagname_s != NULL ); + if( fmt == NULL ) { + res = xmlNewChild(node, NULL, tagname_s, NULL); + goto exit; + } + va_start(ap, fmt); val_s = dmixml_buildstr(2048, fmt, ap); va_end(ap); @@ -144,8 +155,9 @@ xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt res = xmlNewTextChild(node, NULL, tagname_s, (xmlStrcmp(val_s, (xmlChar *) "(null)") == 0 ? NULL : val_s)); - free(tagname_s); free(val_s); + exit: + free(tagname_s); assert( res != NULL ); return res; @@ -165,7 +177,9 @@ xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...) va_list ap; if( (node == NULL) || (fmt == NULL) ) { - return NULL; + // Return node and not NULL, as node may not be NULL but fmt can be, + // thus doing a similar string check (val_s != "(null)") as later on + return node; } va_start(ap, fmt); -- cgit