get rid of all the perror() calls made in the library execution paths.
* 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
Daniel
diff --git a/ChangeLog b/ChangeLog
index 6508302..824c70b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Sep 5 13:29:47 CEST 2002 Daniel Veillard <daniel@veillard.com>
+
+ * 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 <daniel@veillard.com>
* xmllint.c: memory leak reporting was broken after a change
diff --git a/DOCBparser.c b/DOCBparser.c
index 1cb0ebf..e1d20c5 100644
--- a/DOCBparser.c
+++ b/DOCBparser.c
@@ -119,19 +119,20 @@
* 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 @@
* 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 @@
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 @@
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 @@
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 c8e9cca..927cf2c 100644
--- a/HTMLparser.c
+++ b/HTMLparser.c
@@ -1325,9 +1325,9 @@
*/
#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 @@
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 @@
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 @@
if (ctxt == NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlNewParserCtxt : cannot allocate context\n");
- perror("malloc");
return(NULL);
}
memset(ctxt, 0, sizeof(xmlParserCtxt));
@@ -4941,14 +4868,14 @@
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 f10066e..e80536e 100644
--- a/c14n.c
+++ b/c14n.c
@@ -1821,7 +1821,7 @@
buffer = (xmlChar *) \
xmlRealloc(buffer, buffer_size * sizeof(xmlChar)); \
if (buffer == NULL) { \
- perror("realloc failed"); \
+ xmlGenericError(xmlGenericErrorContext, "realloc failed"); \
return(NULL); \
} \
}
@@ -1856,7 +1856,7 @@
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 efc7b9f..dbdf9eb 100644
--- a/entities.c
+++ b/entities.c
@@ -419,9 +419,10 @@
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 @@
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 @@
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 @@
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 @@
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 756912a..18a8297 100644
--- a/list.c
+++ b/list.c
@@ -181,7 +181,8 @@
{
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 @@
/* 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 @@
/* 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 @@
/* 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 @@
/* 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 @@
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 a68b3b9..0374f68 100644
--- a/parser.c
+++ b/parser.c
@@ -931,7 +931,7 @@
buffer = (xmlChar *) \
xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \
if (buffer == NULL) { \
- perror("realloc failed"); \
+ xmlGenericError(xmlGenericErrorContext, "realloc failed"); \
return(NULL); \
} \
}
@@ -984,7 +984,8 @@
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 @@
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 @@
input = xmlNewInputStream(ctxt);
if (input == NULL) {
- perror("malloc");
+ xmlGenericError(xmlGenericErrorContext,
+ "malloc");
xmlFree(ctxt);
return;
}
diff --git a/parserInternals.c b/parserInternals.c
index 8d4e680..ea217ad 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -2351,7 +2351,7 @@
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 @@
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 1c2a122..3cd4c2a 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -2158,7 +2158,6 @@
return(-1);
}
if (res < 0) {
- perror ("read error");
return(-1);
}
len = res;