1818#if defined(HAVE_LIBXML ) && (defined(HAVE_XML ) || defined(HAVE_XMLRPC )) && !defined(HAVE_LIBEXPAT )
1919#include "expat_compat.h"
2020#include "ext/libxml/php_libxml.h"
21+ #include "Zend/zend_smart_string.h"
2122
2223#ifdef LIBXML_EXPAT_COMPAT
2324
@@ -38,31 +39,31 @@ static void
3839start_element_handler (void * user , const xmlChar * name , const xmlChar * * attributes )
3940{
4041 XML_Parser parser = (XML_Parser ) user ;
41- xmlChar * qualified_name = NULL ;
4242
4343 if (parser -> h_start_element == NULL ) {
4444 if (parser -> h_default ) {
4545 int attno = 0 ;
46+ smart_string qualified_name = {0 };
47+
48+ smart_string_appendc (& qualified_name , '<' );
49+ smart_string_appends (& qualified_name , (const char * ) name );
4650
47- qualified_name = xmlStrncatNew ((xmlChar * )"<" , name , xmlStrlen (name ));
4851 if (attributes ) {
4952 while (attributes [attno ] != NULL ) {
50- int att_len ;
51- char * att_string , * att_name , * att_value ;
52-
53- att_name = (char * )attributes [attno ++ ];
54- att_value = (char * )attributes [attno ++ ];
55-
56- att_len = spprintf (& att_string , 0 , " %s=\"%s\"" , att_name , att_value );
57-
58- qualified_name = xmlStrncat (qualified_name , (xmlChar * )att_string , att_len );
59- efree (att_string );
53+ const char * att_name = (const char * ) attributes [attno ++ ];
54+ const char * att_value = (const char * ) attributes [attno ++ ];
55+
56+ smart_string_appendc (& qualified_name , ' ' );
57+ smart_string_appends (& qualified_name , att_name );
58+ smart_string_appends (& qualified_name , "=\"" );
59+ smart_string_appends (& qualified_name , att_value );
60+ smart_string_appendc (& qualified_name , '"' );
6061 }
61-
6262 }
63- qualified_name = xmlStrncat (qualified_name , (xmlChar * )">" , 1 );
64- parser -> h_default (parser -> user , (const XML_Char * ) qualified_name , xmlStrlen (qualified_name ));
65- xmlFree (qualified_name );
63+ smart_string_appendc (& qualified_name , '>' );
64+ smart_string_0 (& qualified_name );
65+ parser -> h_default (parser -> user , (const XML_Char * ) qualified_name .c , qualified_name .len );
66+ smart_string_free (& qualified_name );
6667 }
6768 return ;
6869 }
0 commit comments