mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-23 01:52:48 +03:00
parser: Don't report malloc failures when creating context
We don't want messages to stderr before an error handler could be set on a parser context.
This commit is contained in:
@@ -5817,13 +5817,17 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
|
|||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
encoding = xmlGetCharEncodingName(enc);
|
encoding = xmlGetCharEncodingName(enc);
|
||||||
input = xmlNewInputPush(ctxt, filename, chunk, size, encoding);
|
input = xmlInputCreatePush(filename, chunk, size);
|
||||||
if (input == NULL) {
|
if (input == NULL) {
|
||||||
htmlFreeParserCtxt(ctxt);
|
htmlFreeParserCtxt(ctxt);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
inputPush(ctxt, input);
|
inputPush(ctxt, input);
|
||||||
|
|
||||||
|
if (encoding != NULL)
|
||||||
|
xmlSwitchEncodingName(ctxt, encoding);
|
||||||
|
|
||||||
return(ctxt);
|
return(ctxt);
|
||||||
}
|
}
|
||||||
#endif /* LIBXML_PUSH_ENABLED */
|
#endif /* LIBXML_PUSH_ENABLED */
|
||||||
|
|||||||
@@ -108,8 +108,7 @@ xmlNewInputIO(xmlParserCtxtPtr ctxt, const char *url,
|
|||||||
void *ioCtxt,
|
void *ioCtxt,
|
||||||
const char *encoding, int flags);
|
const char *encoding, int flags);
|
||||||
XML_HIDDEN xmlParserInputPtr
|
XML_HIDDEN xmlParserInputPtr
|
||||||
xmlNewInputPush(xmlParserCtxtPtr ctxt, const char *url,
|
xmlInputCreatePush(const char *url, const char *chunk, int size);
|
||||||
const char *chunk, int size, const char *encoding);
|
|
||||||
|
|
||||||
XML_HIDDEN xmlChar *
|
XML_HIDDEN xmlChar *
|
||||||
xmlExpandEntitiesInAttValue(xmlParserCtxtPtr ctxt, const xmlChar *str,
|
xmlExpandEntitiesInAttValue(xmlParserCtxtPtr ctxt, const xmlChar *str,
|
||||||
|
|||||||
11
parser.c
11
parser.c
@@ -11633,7 +11633,8 @@ xmlParseChunk(xmlParserCtxtPtr ctxt, const char *chunk, int size,
|
|||||||
* @filename is used as base URI to fetch external entities and for
|
* @filename is used as base URI to fetch external entities and for
|
||||||
* error reports.
|
* error reports.
|
||||||
*
|
*
|
||||||
* Returns the new parser context or NULL in case of error.
|
* Returns the new parser context or NULL if a memory allocation
|
||||||
|
* failed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
xmlParserCtxtPtr
|
xmlParserCtxtPtr
|
||||||
@@ -11649,7 +11650,7 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
|
|||||||
ctxt->options &= ~XML_PARSE_NODICT;
|
ctxt->options &= ~XML_PARSE_NODICT;
|
||||||
ctxt->dictNames = 1;
|
ctxt->dictNames = 1;
|
||||||
|
|
||||||
input = xmlNewInputPush(ctxt, filename, chunk, size, NULL);
|
input = xmlInputCreatePush(filename, chunk, size);
|
||||||
if (input == NULL) {
|
if (input == NULL) {
|
||||||
xmlFreeParserCtxt(ctxt);
|
xmlFreeParserCtxt(ctxt);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
@@ -13348,11 +13349,15 @@ xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *chunk,
|
|||||||
|
|
||||||
xmlCtxtReset(ctxt);
|
xmlCtxtReset(ctxt);
|
||||||
|
|
||||||
input = xmlNewInputPush(ctxt, filename, chunk, size, encoding);
|
input = xmlInputCreatePush(filename, chunk, size);
|
||||||
if (input == NULL)
|
if (input == NULL)
|
||||||
return(1);
|
return(1);
|
||||||
|
|
||||||
inputPush(ctxt, input);
|
inputPush(ctxt, input);
|
||||||
|
|
||||||
|
if (encoding != NULL)
|
||||||
|
xmlSwitchEncodingName(ctxt, encoding);
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1100,7 +1100,7 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlSwitchEncodingName:
|
* xmlSwitchInputEncodingName:
|
||||||
* @ctxt: the parser context, only for error reporting
|
* @ctxt: the parser context, only for error reporting
|
||||||
* @input: the input strea,
|
* @input: the input strea,
|
||||||
* @encoding: the encoding name
|
* @encoding: the encoding name
|
||||||
@@ -1899,37 +1899,27 @@ xmlNewInputIO(xmlParserCtxtPtr ctxt, const char *url,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlNewInputPush:
|
* xmlInputCreatePush:
|
||||||
* @ctxt: parser context
|
|
||||||
* @url: base URL (optional)
|
* @url: base URL (optional)
|
||||||
* @chunk: pointer to char array
|
* @chunk: pointer to char array
|
||||||
* @size: size of array
|
* @size: size of array
|
||||||
* @encoding: character encoding (optional)
|
|
||||||
*
|
*
|
||||||
* Creates a new parser input for a push parser.
|
* Creates a new parser input for a push parser.
|
||||||
*
|
*
|
||||||
* Returns a new parser input.
|
* Returns a new parser input or NULL if a memory allocation failed.
|
||||||
*/
|
*/
|
||||||
xmlParserInputPtr
|
xmlParserInputPtr
|
||||||
xmlNewInputPush(xmlParserCtxtPtr ctxt, const char *url,
|
xmlInputCreatePush(const char *url, const char *chunk, int size) {
|
||||||
const char *chunk, int size, const char *encoding) {
|
|
||||||
xmlParserInputBufferPtr buf;
|
xmlParserInputBufferPtr buf;
|
||||||
xmlParserInputPtr input;
|
xmlParserInputPtr input;
|
||||||
|
|
||||||
buf = xmlAllocParserInputBuffer(XML_CHAR_ENCODING_NONE);
|
buf = xmlAllocParserInputBuffer(XML_CHAR_ENCODING_NONE);
|
||||||
if (buf == NULL) {
|
if (buf == NULL)
|
||||||
xmlCtxtErrMemory(ctxt);
|
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
|
||||||
|
|
||||||
input = xmlNewInputInternal(buf, url);
|
input = xmlNewInputInternal(buf, url);
|
||||||
if (input == NULL) {
|
if (input == NULL)
|
||||||
xmlCtxtErrMemory(ctxt);
|
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
|
||||||
|
|
||||||
if (encoding != NULL)
|
|
||||||
xmlSwitchInputEncodingName(ctxt, input, encoding);
|
|
||||||
|
|
||||||
input->flags |= XML_INPUT_PROGRESSIVE;
|
input->flags |= XML_INPUT_PROGRESSIVE;
|
||||||
|
|
||||||
@@ -1939,7 +1929,6 @@ xmlNewInputPush(xmlParserCtxtPtr ctxt, const char *url,
|
|||||||
res = xmlParserInputBufferPush(input->buf, size, chunk);
|
res = xmlParserInputBufferPush(input->buf, size, chunk);
|
||||||
xmlBufResetInput(input->buf->buffer, input);
|
xmlBufResetInput(input->buf->buffer, input);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
xmlCtxtErrIO(ctxt, input->buf->error, NULL);
|
|
||||||
xmlFreeInputStream(input);
|
xmlFreeInputStream(input);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
@@ -2616,10 +2605,8 @@ xmlInitSAXParserCtxt(xmlParserCtxtPtr ctxt, const xmlSAXHandler *sax,
|
|||||||
|
|
||||||
if (ctxt->nsdb == NULL) {
|
if (ctxt->nsdb == NULL) {
|
||||||
ctxt->nsdb = xmlParserNsCreate();
|
ctxt->nsdb = xmlParserNsCreate();
|
||||||
if (ctxt->nsdb == NULL) {
|
if (ctxt->nsdb == NULL)
|
||||||
xmlCtxtErrMemory(ctxt);
|
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user