77 * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88 * Portions Copyright (c) 1994, Regents of the University of California
99 *
10- * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.58 2007/11/15 22:25:16 momjian Exp $
10+ * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.59 2007/11/20 23:14:41 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -1109,12 +1109,14 @@ parse_xml_decl(const xmlChar * str, size_t *lenp,
11091109return XML_ERR_STANDALONE_VALUE ;
11101110p += 1 ;
11111111SKIP_XML_SPACE (p );
1112- if (xmlStrncmp (p , (xmlChar * )"'yes'" ,5 )== 0 || xmlStrncmp (p , (xmlChar * )"\"yes\"" ,5 )== 0 )
1112+ if (xmlStrncmp (p , (xmlChar * )"'yes'" ,5 )== 0 ||
1113+ xmlStrncmp (p , (xmlChar * )"\"yes\"" ,5 )== 0 )
11131114{
11141115* standalone = 1 ;
11151116p += 5 ;
11161117}
1117- else if (xmlStrncmp (p , (xmlChar * )"'no'" ,4 )== 0 || xmlStrncmp (p , (xmlChar * )"\"no\"" ,4 )== 0 )
1118+ else if (xmlStrncmp (p , (xmlChar * )"'no'" ,4 )== 0 ||
1119+ xmlStrncmp (p , (xmlChar * )"\"no\"" ,4 )== 0 )
11181120{
11191121* standalone = 0 ;
11201122p += 4 ;
@@ -3305,6 +3307,8 @@ xpath(PG_FUNCTION_ARGS)
33053307(errcode (ERRCODE_DATA_EXCEPTION ),
33063308errmsg ("empty XPath expression" )));
33073309
3310+ xml_init ();
3311+
33083312/*
33093313 * To handle both documents and fragments, regardless of the fact whether
33103314 * the XML datum has a single root (XML well-formedness), we wrap the XML
@@ -3324,20 +3328,22 @@ xpath(PG_FUNCTION_ARGS)
33243328"could not parse XML data" );
33253329
33263330++ i ;
3327- string = xmlStrncatNew ((xmlChar * )"<x>" ,
3328- (xmlChar * )datastr + i ,len - i );
3331+
3332+ datastr += i ;
3333+ len -= i ;
33293334}
3330- else
3331- string = xmlStrncatNew ((xmlChar * )"<x>" ,
3332- (xmlChar * )datastr ,len );
33333335
3334- string = xmlStrncat (string , (xmlChar * )"</x>" ,5 );
3336+ string = (xmlChar * )palloc ((len + 8 )* sizeof (xmlChar ));
3337+ memcpy (string ,"<x>" ,3 );
3338+ memcpy (string + 3 ,datastr ,len );
3339+ memcpy (string + 3 + len ,"</x>" ,5 );
33353340len += 7 ;
3336- xpath_expr = xmlStrncatNew ((xmlChar * )"/x" ,
3337- (xmlChar * )VARDATA (xpath_expr_text ),xpath_len );
3338- xpath_len += 2 ;
33393341
3340- xml_init ();
3342+ xpath_expr = (xmlChar * )palloc ((xpath_len + 3 )* sizeof (xmlChar ));
3343+ memcpy (xpath_expr ,"/x" ,2 );
3344+ memcpy (xpath_expr + 2 ,VARDATA (xpath_expr_text ),xpath_len );
3345+ xpath_expr [xpath_len + 2 ]= '\0' ;
3346+ xpath_len += 2 ;
33413347
33423348/* We use a PG_TRY block to ensure libxml parser is cleaned up on error */
33433349PG_TRY ();