diff --git a/ChangeLog b/ChangeLog index 6508302d..824c70bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Sep 5 13:29:47 CEST 2002 Daniel Veillard + + * DOCBparser.c HTMLparser.c c14n.c entities.c list.c + parser.c parserInternals.c xmlIO.c: get rid of all the + perror() calls made in the library execution paths. This + should fix both #92059 and #92385 + Thu Sep 5 13:13:17 CEST 2002 Daniel Veillard * xmllint.c: memory leak reporting was broken after a change diff --git a/DOCBparser.c b/DOCBparser.c index 1cb0ebf1..e1d20c58 100644 --- a/DOCBparser.c +++ b/DOCBparser.c @@ -119,19 +119,20 @@ struct _docbElemDesc { * Generic function for accessing stacks in the Parser Context */ -#define PUSH_AND_POP(scope, type, name) \ +#define PUSH_AND_POP(scope, type, name) \ scope int docb##name##Push(docbParserCtxtPtr ctxt, type value) { \ if (ctxt->name##Nr >= ctxt->name##Max) { \ ctxt->name##Max *= 2; \ ctxt->name##Tab = (type *) xmlRealloc(ctxt->name##Tab, \ ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \ if (ctxt->name##Tab == NULL) { \ - xmlGenericError(xmlGenericErrorContext, "realloc failed !\n"); \ + xmlGenericError(xmlGenericErrorContext, \ + "realloc failed !\n"); \ return(0); \ } \ } \ ctxt->name##Tab[ctxt->name##Nr] = value; \ - ctxt->name = value; \ + ctxt->name = value; \ return(ctxt->name##Nr++); \ } \ scope type docb##name##Pop(docbParserCtxtPtr ctxt) { \ @@ -2049,10 +2050,10 @@ docbookEntitiesTable[] = { * Macro used to grow the current buffer. */ #define growBuffer(buffer) { \ - buffer##_size *= 2; \ - buffer = (xmlChar *) xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \ + buffer##_size *= 2; \ + buffer = (xmlChar *) xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \ if (buffer == NULL) { \ - perror("realloc failed"); \ + xmlGenericError(xmlGenericErrorContext, "realloc failed"); \ return(NULL); \ } \ } @@ -2678,7 +2679,8 @@ docbParseSGMLAttribute(docbParserCtxtPtr ctxt, const xmlChar stop) { buffer_size = DOCB_PARSER_BIG_BUFFER_SIZE; buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); if (buffer == NULL) { - perror("docbParseSGMLAttribute: malloc failed"); + xmlGenericError(xmlGenericErrorContext, + "docbParseSGMLAttribute: malloc failed"); return(NULL); } out = buffer; @@ -5001,15 +5003,15 @@ docbCreateDocParserCtxt(xmlChar *cur, const char *encoding ATTRIBUTE_UNUSED) { ctxt = (docbParserCtxtPtr) xmlMalloc(sizeof(docbParserCtxt)); if (ctxt == NULL) { - perror("malloc"); - return(NULL); + xmlGenericError(xmlGenericErrorContext, "malloc failed"); + return(NULL); } docbInitParserCtxt(ctxt); input = (docbParserInputPtr) xmlMalloc(sizeof(docbParserInput)); if (input == NULL) { - perror("malloc"); - xmlFree(ctxt); - return(NULL); + xmlGenericError(xmlGenericErrorContext, "malloc failed"); + xmlFree(ctxt); + return(NULL); } memset(input, 0, sizeof(docbParserInput)); @@ -6010,16 +6012,16 @@ docbCreateFileParserCtxt(const char *filename, ctxt = (docbParserCtxtPtr) xmlMalloc(sizeof(docbParserCtxt)); if (ctxt == NULL) { - perror("malloc"); - return(NULL); + xmlGenericError(xmlGenericErrorContext, "malloc failed"); + return(NULL); } memset(ctxt, 0, sizeof(docbParserCtxt)); docbInitParserCtxt(ctxt); inputStream = (docbParserInputPtr) xmlMalloc(sizeof(docbParserInput)); if (inputStream == NULL) { - perror("malloc"); - xmlFree(ctxt); - return(NULL); + xmlGenericError(xmlGenericErrorContext, "malloc failed"); + xmlFree(ctxt); + return(NULL); } memset(inputStream, 0, sizeof(docbParserInput)); diff --git a/HTMLparser.c b/HTMLparser.c index c8e9cca6..927cf2c7 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -1325,9 +1325,9 @@ static const htmlEntityDesc html40EntitiesTable[] = { */ #define growBuffer(buffer) { \ buffer##_size *= 2; \ - buffer = (xmlChar *) xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \ + buffer = (xmlChar *) xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \ if (buffer == NULL) { \ - perror("realloc failed"); \ + xmlGenericError(xmlGenericErrorContext, "realloc failed\n"); \ return(NULL); \ } \ } @@ -1617,79 +1617,6 @@ htmlDecodeEntities(htmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED, int len ATTRIBUTE_UN deprecated = 1; } return(NULL); -#if 0 - xmlChar *name = NULL; - xmlChar *buffer = NULL; - unsigned int buffer_size = 0; - unsigned int nbchars = 0; - htmlEntityDescPtr ent; - unsigned int max = (unsigned int) len; - int c,l; - - if (ctxt->depth > 40) { - ctxt->errNo = XML_ERR_ENTITY_LOOP; - if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) - ctxt->sax->error(ctxt->userData, - "Detected entity reference loop\n"); - ctxt->wellFormed = 0; - ctxt->disableSAX = 1; - return(NULL); - } - - /* - * allocate a translation buffer. - */ - buffer_size = HTML_PARSER_BIG_BUFFER_SIZE; - buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); - if (buffer == NULL) { - perror("xmlDecodeEntities: malloc failed"); - return(NULL); - } - - /* - * Ok loop until we reach one of the ending char or a size limit. - */ - c = CUR_CHAR(l); - while ((nbchars < max) && (c != end) && - (c != end2) && (c != end3)) { - - if (c == 0) break; - if (((c == '&') && (ctxt->token != '&')) && (NXT(1) == '#')) { - int val = htmlParseCharRef(ctxt); - COPY_BUF(0,buffer,nbchars,val); - NEXTL(l); - } else if ((c == '&') && (ctxt->token != '&')) { - ent = htmlParseEntityRef(ctxt, &name); - if (name != NULL) { - if (ent != NULL) { - int val = ent->value; - COPY_BUF(0,buffer,nbchars,val); - NEXTL(l); - } else { - const xmlChar *cur = name; - - buffer[nbchars++] = '&'; - if (nbchars > buffer_size - HTML_PARSER_BUFFER_SIZE) { - growBuffer(buffer); - } - while (*cur != 0) { - buffer[nbchars++] = *cur++; - } - buffer[nbchars++] = ';'; - } - } - } else { - COPY_BUF(l,buffer,nbchars,c); - NEXTL(l); - if (nbchars > buffer_size - HTML_PARSER_BUFFER_SIZE) { - growBuffer(buffer); - } - } - c = CUR_CHAR(l); - } - buffer[nbchars++] = 0; - return(buffer); -#endif } /************************************************************************ @@ -1989,7 +1916,8 @@ htmlParseHTMLAttribute(htmlParserCtxtPtr ctxt, const xmlChar stop) { buffer_size = HTML_PARSER_BUFFER_SIZE; buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); if (buffer == NULL) { - perror("htmlParseHTMLAttribute: malloc failed"); + xmlGenericError(xmlGenericErrorContext, + "htmlParseHTMLAttribute: malloc failed\n"); return(NULL); } out = buffer; @@ -3830,7 +3758,6 @@ htmlNewParserCtxt(void) if (ctxt == NULL) { xmlGenericError(xmlGenericErrorContext, "xmlNewParserCtxt : cannot allocate context\n"); - perror("malloc"); return(NULL); } memset(ctxt, 0, sizeof(xmlParserCtxt)); @@ -4941,14 +4868,14 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding) ctxt = (htmlParserCtxtPtr) xmlMalloc(sizeof(htmlParserCtxt)); if (ctxt == NULL) { - perror("malloc"); + xmlGenericError(xmlGenericErrorContext, "malloc failed\n"); return(NULL); } memset(ctxt, 0, sizeof(htmlParserCtxt)); htmlInitParserCtxt(ctxt); inputStream = (htmlParserInputPtr) xmlMalloc(sizeof(htmlParserInput)); if (inputStream == NULL) { - perror("malloc"); + xmlGenericError(xmlGenericErrorContext, "malloc failed\n"); xmlFree(ctxt); return(NULL); } diff --git a/c14n.c b/c14n.c index f10066e7..e80536e5 100644 --- a/c14n.c +++ b/c14n.c @@ -1821,7 +1821,7 @@ xmlC14NDocSave(xmlDocPtr doc, xmlNodeSetPtr nodes, buffer = (xmlChar *) \ xmlRealloc(buffer, buffer_size * sizeof(xmlChar)); \ if (buffer == NULL) { \ - perror("realloc failed"); \ + xmlGenericError(xmlGenericErrorContext, "realloc failed"); \ return(NULL); \ } \ } @@ -1856,7 +1856,7 @@ xmlC11NNormalizeString(const xmlChar * input, buffer_size = 1000; buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); if (buffer == NULL) { - perror("malloc failed"); + xmlGenericError(xmlGenericErrorContext, "malloc failed"); return (NULL); } out = buffer; diff --git a/entities.c b/entities.c index efc7b9fd..dbdf9ebf 100644 --- a/entities.c +++ b/entities.c @@ -419,9 +419,10 @@ static xmlChar *static_buffer = NULL; static int growBuffer(void) { static_buffer_size *= 2; - static_buffer = (xmlChar *) xmlRealloc(static_buffer, static_buffer_size * sizeof(xmlChar)); + static_buffer = (xmlChar *) xmlRealloc(static_buffer, + static_buffer_size * sizeof(xmlChar)); if (static_buffer == NULL) { - perror("realloc failed"); + xmlGenericError(xmlGenericErrorContext, "malloc failed\n"); return(-1); } return(0); @@ -466,9 +467,10 @@ xmlEncodeEntities(xmlDocPtr doc, const xmlChar *input) { if (static_buffer == NULL) { static_buffer_size = 1000; - static_buffer = (xmlChar *) xmlMalloc(static_buffer_size * sizeof(xmlChar)); + static_buffer = (xmlChar *) + xmlMalloc(static_buffer_size * sizeof(xmlChar)); if (static_buffer == NULL) { - perror("malloc failed"); + xmlGenericError(xmlGenericErrorContext, "malloc failed\n"); return(NULL); } out = static_buffer; @@ -561,7 +563,7 @@ xmlEncodeEntities(xmlDocPtr doc, const xmlChar *input) { buffer = (xmlChar *) \ xmlRealloc(buffer, buffer_size * sizeof(xmlChar)); \ if (buffer == NULL) { \ - perror("realloc failed"); \ + xmlGenericError(xmlGenericErrorContext, "realloc failed\n"); \ return(NULL); \ } \ } @@ -597,7 +599,7 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) { buffer_size = 1000; buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); if (buffer == NULL) { - perror("malloc failed"); + xmlGenericError(xmlGenericErrorContext, "malloc failed\n"); return(NULL); } out = buffer; @@ -780,7 +782,7 @@ xmlEncodeSpecialChars(xmlDocPtr doc, const xmlChar *input) { buffer_size = 1000; buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); if (buffer == NULL) { - perror("malloc failed"); + xmlGenericError(xmlGenericErrorContext, "malloc failed\n"); return(NULL); } out = buffer; diff --git a/list.c b/list.c index 756912a2..18a82973 100644 --- a/list.c +++ b/list.c @@ -181,7 +181,8 @@ xmlListCreate(xmlListDeallocator deallocator, xmlListDataCompare compare) { xmlListPtr l; if (NULL == (l = (xmlListPtr )xmlMalloc( sizeof(xmlList)))) { - perror("Cannot initialize memory for list"); + xmlGenericError(xmlGenericErrorContext, + "Cannot initialize memory for list"); return (NULL); } /* Initialize the list to NULL */ @@ -189,7 +190,8 @@ xmlListCreate(xmlListDeallocator deallocator, xmlListDataCompare compare) /* Add the sentinel */ if (NULL ==(l->sentinel = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink)))) { - perror("Cannot initialize memory for sentinel"); + xmlGenericError(xmlGenericErrorContext, + "Cannot initialize memory for sentinel"); xmlFree(l); return (NULL); } @@ -264,7 +266,8 @@ xmlListInsert(xmlListPtr l, void *data) /* Add the new link */ lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink)); if (lkNew == NULL) { - perror("Cannot initialize memory for new link"); + xmlGenericError(xmlGenericErrorContext, + "Cannot initialize memory for new link"); return (1); } lkNew->data = data; @@ -293,7 +296,8 @@ int xmlListAppend(xmlListPtr l, void *data) /* Add the new link */ lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink)); if (lkNew == NULL) { - perror("Cannot initialize memory for new link"); + xmlGenericError(xmlGenericErrorContext, + "Cannot initialize memory for new link"); return (0); } lkNew->data = data; @@ -507,7 +511,8 @@ xmlListPushFront(xmlListPtr l, void *data) /* Add the new link */ lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink)); if (lkNew == NULL) { - perror("Cannot initialize memory for new link"); + xmlGenericError(xmlGenericErrorContext, + "Cannot initialize memory for new link"); return (0); } lkNew->data = data; @@ -535,7 +540,8 @@ xmlListPushBack(xmlListPtr l, void *data) lkPlace = l->sentinel->prev; /* Add the new link */ if (NULL ==(lkNew = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink)))) { - perror("Cannot initialize memory for new link"); + xmlGenericError(xmlGenericErrorContext, + "Cannot initialize memory for new link"); return (0); } lkNew->data = data; diff --git a/parser.c b/parser.c index a68b3b91..0374f681 100644 --- a/parser.c +++ b/parser.c @@ -931,7 +931,7 @@ xmlParserHandlePEReference(xmlParserCtxtPtr ctxt) { buffer = (xmlChar *) \ xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \ if (buffer == NULL) { \ - perror("realloc failed"); \ + xmlGenericError(xmlGenericErrorContext, "realloc failed"); \ return(NULL); \ } \ } @@ -984,7 +984,8 @@ xmlStringDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int what, buffer_size = XML_PARSER_BIG_BUFFER_SIZE; buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); if (buffer == NULL) { - perror("xmlStringDecodeEntities: malloc failed"); + xmlGenericError(xmlGenericErrorContext, + "xmlStringDecodeEntities: malloc failed"); return(NULL); } @@ -2341,7 +2342,8 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt) { buf_size = XML_PARSER_BUFFER_SIZE; buf = (xmlChar *) xmlMalloc(buf_size * sizeof(xmlChar)); if (buf == NULL) { - perror("xmlParseAttValue: malloc failed"); + xmlGenericError(xmlGenericErrorContext, + "xmlParseAttValue: malloc failed"); return(NULL); } @@ -10191,7 +10193,8 @@ xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const xmlChar* buffer, input = xmlNewInputStream(ctxt); if (input == NULL) { - perror("malloc"); + xmlGenericError(xmlGenericErrorContext, + "malloc"); xmlFree(ctxt); return; } diff --git a/parserInternals.c b/parserInternals.c index 8d4e680f..ea217ad9 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -2351,7 +2351,7 @@ xmlNewParserCtxt() if (ctxt == NULL) { xmlGenericError(xmlGenericErrorContext, "xmlNewParserCtxt : cannot allocate context\n"); - perror("malloc"); + xmlGenericError(xmlGenericErrorContext, "malloc failed"); return(NULL); } memset(ctxt, 0, sizeof(xmlParserCtxt)); @@ -2767,7 +2767,8 @@ xmlDecodeEntities(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUS buffer_size = XML_PARSER_BIG_BUFFER_SIZE; buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar)); if (buffer == NULL) { - perror("xmlDecodeEntities: malloc failed"); + xmlGenericError(xmlGenericErrorContext, + "xmlDecodeEntities: malloc failed"); return(NULL); } diff --git a/xmlIO.c b/xmlIO.c index 1c2a1226..3cd4c2ae 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -2158,7 +2158,6 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) { return(-1); } if (res < 0) { - perror ("read error"); return(-1); } len = res;