diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/libxml/parserInternals.c | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) | |
download | ydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/libxml/parserInternals.c')
-rw-r--r-- | contrib/libs/libxml/parserInternals.c | 262 |
1 files changed, 131 insertions, 131 deletions
diff --git a/contrib/libs/libxml/parserInternals.c b/contrib/libs/libxml/parserInternals.c index 271de8816e..b00cd08ec2 100644 --- a/contrib/libs/libxml/parserInternals.c +++ b/contrib/libs/libxml/parserInternals.c @@ -10,7 +10,7 @@ #define IN_LIBXML #include "libxml.h" -#if defined(_WIN32) && !defined (__CYGWIN__) +#if defined(_WIN32) && !defined (__CYGWIN__) #define XML_DIR_SEP '\\' #else #define XML_DIR_SEP '/' @@ -32,8 +32,8 @@ #ifdef HAVE_UNISTD_H #include <unistd.h> #endif -#ifdef LIBXML_ZLIB_ENABLED -#include <zlib.h> +#ifdef LIBXML_ZLIB_ENABLED +#include <zlib.h> #endif #include <libxml/xmlmemory.h> @@ -55,10 +55,10 @@ #include <libxml/globals.h> #include <libxml/chvalid.h> -#define CUR(ctxt) ctxt->input->cur -#define END(ctxt) ctxt->input->end -#define VALID_CTXT(ctxt) (CUR(ctxt) <= END(ctxt)) - +#define CUR(ctxt) ctxt->input->cur +#define END(ctxt) ctxt->input->end +#define VALID_CTXT(ctxt) (CUR(ctxt) <= END(ctxt)) + #include "buf.h" #include "enc.h" @@ -169,7 +169,7 @@ __xmlErrEncoding(xmlParserCtxtPtr ctxt, xmlParserErrors xmlerr, * * Handle an internal error */ -static void LIBXML_ATTR_FORMAT(2,0) +static void LIBXML_ATTR_FORMAT(2,0) xmlErrInternal(xmlParserCtxtPtr ctxt, const char *msg, const xmlChar * str) { if ((ctxt != NULL) && (ctxt->disableSAX != 0) && @@ -197,7 +197,7 @@ xmlErrInternal(xmlParserCtxtPtr ctxt, const char *msg, const xmlChar * str) * * n encoding error */ -static void LIBXML_ATTR_FORMAT(3,0) +static void LIBXML_ATTR_FORMAT(3,0) xmlErrEncodingInt(xmlParserCtxtPtr ctxt, xmlParserErrors error, const char *msg, int val) { @@ -298,7 +298,7 @@ xmlParserInputRead(xmlParserInputPtr in ATTRIBUTE_UNUSED, int len ATTRIBUTE_UNUS */ int xmlParserInputGrow(xmlParserInputPtr in, int len) { - int ret; + int ret; size_t indx; const xmlChar *content; @@ -426,101 +426,101 @@ xmlNextChar(xmlParserCtxtPtr ctxt) (ctxt->input == NULL)) return; - if (!(VALID_CTXT(ctxt))) { - xmlErrInternal(ctxt, "Parser input data memory error\n", NULL); - ctxt->errNo = XML_ERR_INTERNAL_ERROR; - xmlStopParser(ctxt); - return; - } - - if ((*ctxt->input->cur == 0) && - (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) { - return; - } - + if (!(VALID_CTXT(ctxt))) { + xmlErrInternal(ctxt, "Parser input data memory error\n", NULL); + ctxt->errNo = XML_ERR_INTERNAL_ERROR; + xmlStopParser(ctxt); + return; + } + + if ((*ctxt->input->cur == 0) && + (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) { + return; + } + if (ctxt->charset == XML_CHAR_ENCODING_UTF8) { - const unsigned char *cur; - unsigned char c; - - /* - * 2.11 End-of-Line Handling - * the literal two-character sequence "#xD#xA" or a standalone - * literal #xD, an XML processor must pass to the application - * the single character #xA. - */ - if (*(ctxt->input->cur) == '\n') { - ctxt->input->line++; ctxt->input->col = 1; - } else - ctxt->input->col++; - - /* - * We are supposed to handle UTF8, check it's valid - * From rfc2044: encoding of the Unicode values on UTF-8: - * - * UCS-4 range (hex.) UTF-8 octet sequence (binary) - * 0000 0000-0000 007F 0xxxxxxx - * 0000 0080-0000 07FF 110xxxxx 10xxxxxx - * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx - * - * Check for the 0x110000 limit too - */ - cur = ctxt->input->cur; - - c = *cur; - if (c & 0x80) { - if (c == 0xC0) - goto encoding_error; - if (cur[1] == 0) { - xmlParserInputGrow(ctxt->input, INPUT_CHUNK); - cur = ctxt->input->cur; - } - if ((cur[1] & 0xc0) != 0x80) - goto encoding_error; - if ((c & 0xe0) == 0xe0) { - unsigned int val; - - if (cur[2] == 0) { + const unsigned char *cur; + unsigned char c; + + /* + * 2.11 End-of-Line Handling + * the literal two-character sequence "#xD#xA" or a standalone + * literal #xD, an XML processor must pass to the application + * the single character #xA. + */ + if (*(ctxt->input->cur) == '\n') { + ctxt->input->line++; ctxt->input->col = 1; + } else + ctxt->input->col++; + + /* + * We are supposed to handle UTF8, check it's valid + * From rfc2044: encoding of the Unicode values on UTF-8: + * + * UCS-4 range (hex.) UTF-8 octet sequence (binary) + * 0000 0000-0000 007F 0xxxxxxx + * 0000 0080-0000 07FF 110xxxxx 10xxxxxx + * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx + * + * Check for the 0x110000 limit too + */ + cur = ctxt->input->cur; + + c = *cur; + if (c & 0x80) { + if (c == 0xC0) + goto encoding_error; + if (cur[1] == 0) { + xmlParserInputGrow(ctxt->input, INPUT_CHUNK); + cur = ctxt->input->cur; + } + if ((cur[1] & 0xc0) != 0x80) + goto encoding_error; + if ((c & 0xe0) == 0xe0) { + unsigned int val; + + if (cur[2] == 0) { xmlParserInputGrow(ctxt->input, INPUT_CHUNK); cur = ctxt->input->cur; } - if ((cur[2] & 0xc0) != 0x80) + if ((cur[2] & 0xc0) != 0x80) goto encoding_error; - if ((c & 0xf0) == 0xf0) { - if (cur[3] == 0) { + if ((c & 0xf0) == 0xf0) { + if (cur[3] == 0) { xmlParserInputGrow(ctxt->input, INPUT_CHUNK); cur = ctxt->input->cur; } - if (((c & 0xf8) != 0xf0) || - ((cur[3] & 0xc0) != 0x80)) + if (((c & 0xf8) != 0xf0) || + ((cur[3] & 0xc0) != 0x80)) goto encoding_error; - /* 4-byte code */ - ctxt->input->cur += 4; - val = (cur[0] & 0x7) << 18; - val |= (cur[1] & 0x3f) << 12; - val |= (cur[2] & 0x3f) << 6; - val |= cur[3] & 0x3f; - } else { - /* 3-byte code */ - ctxt->input->cur += 3; - val = (cur[0] & 0xf) << 12; - val |= (cur[1] & 0x3f) << 6; - val |= cur[2] & 0x3f; - } - if (((val > 0xd7ff) && (val < 0xe000)) || - ((val > 0xfffd) && (val < 0x10000)) || - (val >= 0x110000)) { - xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR, - "Char 0x%X out of allowed range\n", - val); - } + /* 4-byte code */ + ctxt->input->cur += 4; + val = (cur[0] & 0x7) << 18; + val |= (cur[1] & 0x3f) << 12; + val |= (cur[2] & 0x3f) << 6; + val |= cur[3] & 0x3f; + } else { + /* 3-byte code */ + ctxt->input->cur += 3; + val = (cur[0] & 0xf) << 12; + val |= (cur[1] & 0x3f) << 6; + val |= cur[2] & 0x3f; + } + if (((val > 0xd7ff) && (val < 0xe000)) || + ((val > 0xfffd) && (val < 0x10000)) || + (val >= 0x110000)) { + xmlErrEncodingInt(ctxt, XML_ERR_INVALID_CHAR, + "Char 0x%X out of allowed range\n", + val); + } } else - /* 2-byte code */ - ctxt->input->cur += 2; - } else - /* 1-byte code */ - ctxt->input->cur++; + /* 2-byte code */ + ctxt->input->cur += 2; + } else + /* 1-byte code */ + ctxt->input->cur++; - ctxt->nbChars++; + ctxt->nbChars++; } else { /* * Assume it's a fixed length encoding (1) with @@ -535,8 +535,8 @@ xmlNextChar(xmlParserCtxtPtr ctxt) ctxt->input->cur++; ctxt->nbChars++; } - if (*ctxt->input->cur == 0) - xmlParserInputGrow(ctxt->input, INPUT_CHUNK); + if (*ctxt->input->cur == 0) + xmlParserInputGrow(ctxt->input, INPUT_CHUNK); return; encoding_error: /* @@ -703,7 +703,7 @@ encoding_error: /* * An encoding problem may arise from a truncated input buffer * splitting a character in the middle. In that case do not raise - * an error but return 0 to indicate an end of stream problem + * an error but return 0 to indicate an end of stream problem */ if (ctxt->input->end - ctxt->input->cur < 4) { *len = 0; @@ -816,7 +816,7 @@ encoding_error: /* * An encoding problem may arise from a truncated input buffer * splitting a character in the middle. In that case do not raise - * an error but return 0 to indicate an end of stream problem + * an error but return 0 to indicate an end of stream problem */ if ((ctxt == NULL) || (ctxt->input == NULL) || (ctxt->input->end - ctxt->input->cur < 4)) { @@ -934,7 +934,7 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc) { xmlCharEncodingHandlerPtr handler; int len = -1; - int ret; + int ret; if (ctxt == NULL) return(-1); switch (enc) { @@ -1092,25 +1092,25 @@ xmlSwitchEncoding(xmlParserCtxtPtr ctxt, xmlCharEncoding enc) break; } } - /* - * TODO: We could recover from errors in external entities if we - * didn't stop the parser. But most callers of this function don't - * check the return value. - */ - if (handler == NULL) { - xmlStopParser(ctxt); + /* + * TODO: We could recover from errors in external entities if we + * didn't stop the parser. But most callers of this function don't + * check the return value. + */ + if (handler == NULL) { + xmlStopParser(ctxt); return(-1); - } + } ctxt->charset = XML_CHAR_ENCODING_UTF8; - ret = xmlSwitchToEncodingInt(ctxt, handler, len); - if ((ret < 0) || (ctxt->errNo == XML_I18N_CONV_FAILED)) { - /* - * on encoding conversion errors, stop the parser - */ - xmlStopParser(ctxt); - ctxt->errNo = XML_I18N_CONV_FAILED; - } - return(ret); + ret = xmlSwitchToEncodingInt(ctxt, handler, len); + if ((ret < 0) || (ctxt->errNo == XML_I18N_CONV_FAILED)) { + /* + * on encoding conversion errors, stop the parser + */ + xmlStopParser(ctxt); + ctxt->errNo = XML_I18N_CONV_FAILED; + } + return(ret); } /** @@ -1138,7 +1138,7 @@ xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, if (input->buf != NULL) { if (input->buf->encoder != NULL) { /* - * Check in case the auto encoding detection triggered + * Check in case the auto encoding detection triggered * in already. */ if (input->buf->encoder == handler) @@ -1224,7 +1224,7 @@ xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, */ nbchars = xmlCharEncFirstLineInput(input->buf, len); } - xmlBufResetInput(input->buf->buffer, input); + xmlBufResetInput(input->buf->buffer, input); if (nbchars < 0) { xmlErrInternal(ctxt, "switching encoding: encoder error\n", @@ -1240,18 +1240,18 @@ xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, * size to be able to convert the buffer. */ xmlErrInternal(ctxt, "switching encoding : no input\n", NULL); - /* - * Callers assume that the input buffer takes ownership of the - * encoding handler. xmlCharEncCloseFunc frees unregistered - * handlers and avoids a memory leak. - */ - xmlCharEncCloseFunc(handler); + /* + * Callers assume that the input buffer takes ownership of the + * encoding handler. xmlCharEncCloseFunc frees unregistered + * handlers and avoids a memory leak. + */ + xmlCharEncCloseFunc(handler); return (-1); } - /* - * We should actually raise an error here, see issue #34. - */ - xmlCharEncCloseFunc(handler); + /* + * We should actually raise an error here, see issue #34. + */ + xmlCharEncCloseFunc(handler); return (0); } @@ -1473,8 +1473,8 @@ xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { if (entity->URI != NULL) input->filename = (char *) xmlStrdup((xmlChar *) entity->URI); input->base = entity->content; - if (entity->length == 0) - entity->length = xmlStrlen(entity->content); + if (entity->length == 0) + entity->length = xmlStrlen(entity->content); input->cur = entity->content; input->length = entity->length; input->end = &entity->content[input->length]; @@ -1805,7 +1805,7 @@ xmlFreeParserCtxt(xmlParserCtxtPtr ctxt) if (ctxt->pushTab != NULL) xmlFree(ctxt->pushTab); if (ctxt->attallocs != NULL) xmlFree(ctxt->attallocs); if (ctxt->attsDefault != NULL) - xmlHashFree(ctxt->attsDefault, xmlHashDefaultDeallocator); + xmlHashFree(ctxt->attsDefault, xmlHashDefaultDeallocator); if (ctxt->attsSpecial != NULL) xmlHashFree(ctxt->attsSpecial, NULL); if (ctxt->freeElems != NULL) { |