From 51e3b154bf9b4abd5a68577aad19120d3d3e1eba Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Fri, 12 Nov 1999 17:02:31 +0000 Subject: [PATCH] xmlSetProp() and xmlNewProp() fixes, mem extra alloc bug in parser fixed, Daniel --- ChangeLog | 10 ++++++++++ HTMLparser.c | 2 +- include/libxml/valid.h | 2 +- parser.c | 28 ++++++++++++++-------------- tree.c | 16 ++++++++++++---- valid.c | 3 +-- valid.h | 2 +- 7 files changed, 40 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2cc46617..26e32f07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Fri Nov 12 17:41:20 CET 1999 Daniel Veillard + + * valid.[ch] : removed a typo and an enumerated type bug in the + xmlAddElementDecl() function + * tree.c : I changed xmlSetProp() and xmlNewProp() to do the + call to xmlEncodeEntitiesReentrant() so that the functions + New, Set and Get are at the same level. + * parser.c HTMLparser.c: extra memory allocation bug for + attributes detected by someone using libxml in embedded systems :-) + Thu Oct 28 17:49:26 CEST 1999 Daniel Veillard * xmlmemory.h: turned off mem debug :-\ diff --git a/HTMLparser.c b/HTMLparser.c index 736dfb06..40b4cf9b 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -1993,7 +1993,7 @@ htmlParseStartTag(htmlParserCtxtPtr ctxt) { if (name != NULL) xmlFree(name); return; } - } else if (nbatts + 2 < maxatts) { + } else if (nbatts + 4 > maxatts) { maxatts *= 2; atts = (const xmlChar **) xmlRealloc(atts, maxatts * sizeof(xmlChar *)); if (atts == NULL) { diff --git a/include/libxml/valid.h b/include/libxml/valid.h index 8c016a93..dc3206fc 100644 --- a/include/libxml/valid.h +++ b/include/libxml/valid.h @@ -120,7 +120,7 @@ void xmlFreeElementContent(xmlElementContentPtr cur); xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, const xmlChar *name, - xmlElementContentType type, + xmlElementTypeVal type, xmlElementContentPtr content); xmlElementTablePtr xmlCopyElementTable (xmlElementTablePtr table); void xmlFreeElementTable (xmlElementTablePtr table); diff --git a/parser.c b/parser.c index 83151fe6..207e6496 100644 --- a/parser.c +++ b/parser.c @@ -379,7 +379,7 @@ xmlPushInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr input) { /** * xmlFreeInputStream: - * @input: an xmlP arserInputPtr + * @input: an xmlParserInputPtr * * Free up an input stream. */ @@ -887,7 +887,7 @@ fprintf(stderr, "xmlParserHandleReference : ctxt->token != 0\n"); case XML_PARSER_ENTITY_VALUE: /* * NOTE: in the case of entity values, we don't do the - * substitution here since we need the litteral + * substitution here since we need the literal * entity value to be able to save the internal * subset of the document. * This will be handled by xmlDecodeEntities @@ -928,7 +928,7 @@ fprintf(stderr, "xmlParserHandleReference : ctxt->token != 0\n"); case XML_PARSER_ENTITY_VALUE: /* * NOTE: in the case of entity values, we don't do the - * substitution here since we need the litteral + * substitution here since we need the literal * entity value to be able to save the internal * subset of the document. * This will be handled by xmlDecodeEntities @@ -1103,7 +1103,7 @@ fprintf(stderr, "xmlParserHandlePEReference : ctxt->token != 0\n"); case XML_PARSER_ENTITY_VALUE: /* * NOTE: in the case of entity values, we don't do the - * substitution here since we need the litteral + * substitution here since we need the literal * entity value to be able to save the internal * subset of the document. * This will be handled by xmlDecodeEntities @@ -1690,7 +1690,7 @@ xmlStrsub(const xmlChar *str, int start, int len) { * xmlStrlen: * @str: the xmlChar * array * - * lenght of a xmlChar's string + * length of a xmlChar's string * * Returns the number of xmlChar contained in the ARRAY. */ @@ -1921,7 +1921,7 @@ xmlNamespaceParseNCName(xmlParserCtxtPtr ctxt) { * * [NS 7] LocalPart ::= NCName * - * Returns the function returns the local part, and prefix is updated + * Returns the local part, and prefix is updated * to get the Prefix if any. */ @@ -1953,7 +1953,7 @@ xmlNamespaceParseQName(xmlParserCtxtPtr ctxt, xmlChar **prefix) { * * [NS 7] LocalPart ::= NCName * - * Returns the function returns the local part, and prefix is updated + * Returns the local part, and prefix is updated * to get the Prefix if any. */ @@ -2082,7 +2082,7 @@ xmlParseQuotedString(xmlParserCtxtPtr ctxt) { * * This is what the older xml-name Working Draft specified, a bunch of * other stuff may still rely on it, so support is still here as - * if ot was declared on the root of the Tree:-( + * if it was declared on the root of the Tree:-( * * To be removed at next drop of binary compatibility */ @@ -5033,7 +5033,7 @@ xmlParseStartTag(xmlParserCtxtPtr ctxt) { maxatts * (long)sizeof(xmlChar *)); return(NULL); } - } else if (nbatts + 2 < maxatts) { + } else if (nbatts + 4 > maxatts) { maxatts *= 2; atts = (const xmlChar **) xmlRealloc(atts, maxatts * sizeof(xmlChar *)); @@ -6332,7 +6332,7 @@ xmlRecoverFile(const char *filename) { /** * xmlCreateMemoryParserCtxt : * @buffer: an pointer to a char array - * @size: the siwe of the array + * @size: the size of the array * * Create a parser context for an XML in-memory document. * @@ -6381,8 +6381,8 @@ xmlCreateMemoryParserCtxt(char *buffer, int size) { * xmlSAXParseMemory : * @sax: the SAX handler block * @buffer: an pointer to a char array - * @size: the siwe of the array - * @recovery: work in recovery mode, i.e. tries to read no Well Formed + * @size: the size of the array + * @recovery: work in recovery mode, i.e. tries to read not Well Formed * documents * * parse an XML in-memory block and use the given SAX function block @@ -6522,7 +6522,7 @@ int xmlSAXUserParseFile(xmlSAXHandlerPtr sax, void *user_data, * @sax: a SAX handler * @user_data: The user data returned on SAX callbacks * @buffer: an in-memory XML document input - * @size: the lenght of the XML document in bytes + * @size: the length of the XML document in bytes * * A better SAX parsing routine. * parse an XML in-memory buffer and call the given SAX handler routines. @@ -6559,7 +6559,7 @@ int xmlSAXUserParseMemory(xmlSAXHandlerPtr sax, void *user_data, /************************************************************************ * * - * Miscelaneous * + * Miscellaneous * * * ************************************************************************/ diff --git a/tree.c b/tree.c index b5d91557..23819a16 100644 --- a/tree.c +++ b/tree.c @@ -753,8 +753,12 @@ xmlNewProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { cur->node = node; cur->ns = NULL; cur->name = xmlStrdup(name); - if (value != NULL) - cur->val = xmlStringGetNodeList(node->doc, value); + if (value != NULL) { + xmlChar *buffer; + buffer = xmlEncodeEntitiesReentrant(node->doc, value); + cur->val = xmlStringGetNodeList(node->doc, buffer); + xmlFree(buffer); + } else cur->val = NULL; #ifndef XML_WITHOUT_CORBA @@ -2406,8 +2410,12 @@ xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { if (prop->val != NULL) xmlFreeNodeList(prop->val); prop->val = NULL; - if (value != NULL) - prop->val = xmlStringGetNodeList(node->doc, value); + if (value != NULL) { + xmlChar *buffer; + buffer = xmlEncodeEntitiesReentrant(node->doc, value); + prop->val = xmlStringGetNodeList(node->doc, buffer); + xmlFree(buffer); + } return(prop); } prop = prop->next; diff --git a/valid.c b/valid.c index 901b030a..691da4ad 100644 --- a/valid.c +++ b/valid.c @@ -309,7 +309,7 @@ xmlCreateElementTable(void) { */ xmlElementPtr xmlAddElementDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, const xmlChar *name, - xmlElementContentType type, xmlElementContentPtr content) { + xmlElementTypeVal type, xmlElementContentPtr content) { xmlElementPtr ret, cur; xmlElementTablePtr table; int i; @@ -2059,7 +2059,6 @@ xmlValidateNmtokenValue(const xmlChar *value) { if (*cur != 0) return(0); return(1); - return(1); } /** diff --git a/valid.h b/valid.h index 8c016a93..dc3206fc 100644 --- a/valid.h +++ b/valid.h @@ -120,7 +120,7 @@ void xmlFreeElementContent(xmlElementContentPtr cur); xmlElementPtr xmlAddElementDecl (xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, const xmlChar *name, - xmlElementContentType type, + xmlElementTypeVal type, xmlElementContentPtr content); xmlElementTablePtr xmlCopyElementTable (xmlElementTablePtr table); void xmlFreeElementTable (xmlElementTablePtr table);