From eaf5f6782d7d1463e96d60c34bcae305e3dd7746 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sat, 29 May 2021 08:38:34 -0400 Subject: [PATCH] Use strlen() internally when computing string lengths Replaces internal `xmlStrlen` calls to use `xmlStrlenFast` which wraps the POSIX / ISO C strlen(). This should be faster on a wide range of platforms. Closes #212. --- HTMLparser.c | 8 ++++---- SAX2.c | 2 +- buf.c | 4 ++-- c14n.c | 22 +++++++++++----------- catalog.c | 16 ++++++++-------- debugXML.c | 2 +- entities.c | 2 +- error.c | 8 ++++---- libxml.h | 14 ++++++++++++++ parser.c | 20 ++++++++++---------- parserInternals.c | 4 ++-- relaxng.c | 2 +- rngparser.c | 2 +- schematron.c | 2 +- tree.c | 14 +++++++------- uri.c | 6 +++--- valid.c | 8 ++++---- xmlreader.c | 12 ++++++------ xmlsave.c | 4 ++-- xmlschemas.c | 4 ++-- xmlstring.c | 10 +++++----- xmlwriter.c | 2 +- xpath.c | 12 ++++++------ xpointer.c | 18 +++++++++--------- 24 files changed, 106 insertions(+), 92 deletions(-) diff --git a/HTMLparser.c b/HTMLparser.c index eba2d7c96..c7a1ba1df 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -3103,7 +3103,7 @@ htmlParseScript(htmlParserCtxtPtr ctxt) { */ if (ctxt->recovery) { if (xmlStrncasecmp(ctxt->name, ctxt->input->cur+2, - xmlStrlen(ctxt->name)) == 0) + xmlStrlenFast(ctxt->name)) == 0) { break; /* while */ } else { @@ -4293,7 +4293,7 @@ htmlParseReference(htmlParserCtxtPtr ctxt) { htmlCheckParagraph(ctxt); if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL)) { ctxt->sax->characters(ctxt->userData, BAD_CAST "&", 1); - ctxt->sax->characters(ctxt->userData, name, xmlStrlen(name)); + ctxt->sax->characters(ctxt->userData, name, xmlStrlenFast(name)); /* ctxt->sax->characters(ctxt->userData, BAD_CAST ";", 1); */ } } else { @@ -5230,7 +5230,7 @@ htmlCreateDocParserCtxt(const xmlChar *cur, const char *encoding) { if (cur == NULL) return(NULL); - len = xmlStrlen(cur); + len = xmlStrlenFast(cur); ctxt = htmlCreateMemoryParserCtxt((char *)cur, len); if (ctxt == NULL) return(NULL); @@ -6487,7 +6487,7 @@ htmlCreateFileParserCtxt(const char *filename, const char *encoding) size_t l = strlen(encoding); if (l < 1000) { - content = xmlMallocAtomic (xmlStrlen(content_line) + l + 1); + content = xmlMallocAtomic (xmlStrlenFast(content_line) + l + 1); if (content) { strcpy ((char *)content, (char *)content_line); strcat ((char *)content, (char *)encoding); diff --git a/SAX2.c b/SAX2.c index 23cfac608..5a255542e 100644 --- a/SAX2.c +++ b/SAX2.c @@ -2613,7 +2613,7 @@ xmlSAX2Text(xmlParserCtxtPtr ctxt, const xmlChar *ch, int len, xmlSAX2ErrMemory(ctxt, "xmlSAX2Characters"); } if (ctxt->node->children != NULL) { - ctxt->nodelen = xmlStrlen(lastChild->content); + ctxt->nodelen = xmlStrlenFast(lastChild->content); ctxt->nodemem = ctxt->nodelen + 1; } } else { diff --git a/buf.c b/buf.c index 11be3c64b..3de89d709 100644 --- a/buf.c +++ b/buf.c @@ -883,7 +883,7 @@ xmlBufAdd(xmlBufPtr buf, const xmlChar *str, int len) { if (len == 0) return 0; if (len < 0) - len = xmlStrlen(str); + len = xmlStrlenFast(str); if (len < 0) return -1; if (len == 0) return 0; @@ -949,7 +949,7 @@ xmlBufAddHead(xmlBufPtr buf, const xmlChar *str, int len) { if (len == 0) return 0; if (len < 0) - len = xmlStrlen(str); + len = xmlStrlenFast(str); if (len <= 0) return -1; diff --git a/c14n.c b/c14n.c index 82f2751f4..1339f70e2 100644 --- a/c14n.c +++ b/c14n.c @@ -642,7 +642,7 @@ xmlC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) if(!already_rendered) { xmlListInsert(list, ns); } - if(xmlStrlen(ns->prefix) == 0) { + if(xmlStrlenFast(ns->prefix) == 0) { has_empty_ns = 1; } } @@ -771,7 +771,7 @@ xmlExcC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) if(!already_rendered) { xmlListInsert(list, ns); } - if(xmlStrlen(ns->prefix) == 0) { + if(xmlStrlenFast(ns->prefix) == 0) { has_empty_ns = 1; } } @@ -794,7 +794,7 @@ xmlExcC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) if(visible) { xmlC14NVisibleNsStackAdd(ctx->ns_rendered, ns, cur); } - if(xmlStrlen(ns->prefix) == 0) { + if(xmlStrlenFast(ns->prefix) == 0) { has_empty_ns = 1; } } @@ -813,10 +813,10 @@ xmlExcC14NProcessNamespacesAxis(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) if(!already_rendered && visible) { xmlListInsert(list, attr->ns); } - if(xmlStrlen(attr->ns->prefix) == 0) { + if(xmlStrlenFast(attr->ns->prefix) == 0) { has_empty_ns = 1; } - } else if((attr->ns != NULL) && (xmlStrlen(attr->ns->prefix) == 0) && (xmlStrlen(attr->ns->href) == 0)) { + } else if((attr->ns != NULL) && (xmlStrlenFast(attr->ns->prefix) == 0) && (xmlStrlenFast(attr->ns->href) == 0)) { has_visibly_utilized_empty_ns = 1; } } @@ -954,7 +954,7 @@ xmlC14NPrintAttrs(const void *data, void *user) } xmlOutputBufferWriteString(ctx->buf, " "); - if (attr->ns != NULL && xmlStrlen(attr->ns->prefix) > 0) { + if (attr->ns != NULL && xmlStrlenFast(attr->ns->prefix) > 0) { xmlOutputBufferWriteString(ctx->buf, (const char *) attr->ns->prefix); xmlOutputBufferWriteString(ctx->buf, ":"); @@ -1047,7 +1047,7 @@ xmlC14NFixupBaseAttr(xmlC14NCtxPtr ctx, xmlAttrPtr xml_base_attr) /* we need to add '/' if our current base uri ends with '..' or '.' to ensure that we are forced to go "up" all the time */ - tmp_str_len = xmlStrlen(tmp_str); + tmp_str_len = xmlStrlenFast(tmp_str); if(tmp_str_len > 1 && tmp_str[tmp_str_len - 2] == '.') { tmp_str2 = xmlStrcat(tmp_str, BAD_CAST "/"); if(tmp_str2 == NULL) { @@ -1374,7 +1374,7 @@ xmlC14NCheckForRelativeNamespaces(xmlC14NCtxPtr ctx, xmlNodePtr cur) ns = cur->nsDef; while (ns != NULL) { - if (xmlStrlen(ns->href) > 0) { + if (xmlStrlenFast(ns->href) > 0) { xmlURIPtr uri; uri = xmlParseURI((const char *) ns->href); @@ -1382,7 +1382,7 @@ xmlC14NCheckForRelativeNamespaces(xmlC14NCtxPtr ctx, xmlNodePtr cur) xmlC14NErrInternal("parsing namespace uri"); return (-1); } - if (xmlStrlen((const xmlChar *) uri->scheme) == 0) { + if (xmlStrlenFast((const xmlChar *) uri->scheme) == 0) { xmlC14NErrRelativeNamespace(uri->scheme); xmlFreeURI(uri); return (-1); @@ -1455,7 +1455,7 @@ xmlC14NProcessElementNode(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) } xmlOutputBufferWriteString(ctx->buf, "<"); - if ((cur->ns != NULL) && (xmlStrlen(cur->ns->prefix) > 0)) { + if ((cur->ns != NULL) && (xmlStrlenFast(cur->ns->prefix) > 0)) { xmlOutputBufferWriteString(ctx->buf, (const char *) cur->ns->prefix); xmlOutputBufferWriteString(ctx->buf, ":"); @@ -1495,7 +1495,7 @@ xmlC14NProcessElementNode(xmlC14NCtxPtr ctx, xmlNodePtr cur, int visible) } if (visible) { xmlOutputBufferWriteString(ctx->buf, "ns != NULL) && (xmlStrlen(cur->ns->prefix) > 0)) { + if ((cur->ns != NULL) && (xmlStrlenFast(cur->ns->prefix) > 0)) { xmlOutputBufferWriteString(ctx->buf, (const char *) cur->ns->prefix); xmlOutputBufferWriteString(ctx->buf, ":"); diff --git a/catalog.c b/catalog.c index f559978cc..2b7cce4f0 100644 --- a/catalog.c +++ b/catalog.c @@ -1669,7 +1669,7 @@ xmlCatalogXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID, } break; case XML_CATA_REWRITE_SYSTEM: - len = xmlStrlen(cur->name); + len = xmlStrlenFast(cur->name); if ((len > lenrewrite) && (!xmlStrncmp(sysID, cur->name, len))) { lenrewrite = len; @@ -1677,7 +1677,7 @@ xmlCatalogXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID, } break; case XML_CATA_DELEGATE_SYSTEM: - if (!xmlStrncmp(sysID, cur->name, xmlStrlen(cur->name))) + if (!xmlStrncmp(sysID, cur->name, xmlStrlenFast(cur->name))) haveDelegate++; break; case XML_CATA_NEXT_CATALOG: @@ -1709,7 +1709,7 @@ xmlCatalogXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID, cur = catal; while (cur != NULL) { if ((cur->type == XML_CATA_DELEGATE_SYSTEM) && - (!xmlStrncmp(sysID, cur->name, xmlStrlen(cur->name)))) { + (!xmlStrncmp(sysID, cur->name, xmlStrlenFast(cur->name)))) { for (i = 0;i < nbList;i++) if (xmlStrEqual(cur->URL, delegates[i])) break; @@ -1762,7 +1762,7 @@ xmlCatalogXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID, } break; case XML_CATA_DELEGATE_PUBLIC: - if (!xmlStrncmp(pubID, cur->name, xmlStrlen(cur->name)) && + if (!xmlStrncmp(pubID, cur->name, xmlStrlenFast(cur->name)) && (cur->prefer == XML_CATA_PREFER_PUBLIC)) haveDelegate++; break; @@ -1787,7 +1787,7 @@ xmlCatalogXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID, while (cur != NULL) { if ((cur->type == XML_CATA_DELEGATE_PUBLIC) && (cur->prefer == XML_CATA_PREFER_PUBLIC) && - (!xmlStrncmp(pubID, cur->name, xmlStrlen(cur->name)))) { + (!xmlStrncmp(pubID, cur->name, xmlStrlenFast(cur->name)))) { for (i = 0;i < nbList;i++) if (xmlStrEqual(cur->URL, delegates[i])) @@ -1900,7 +1900,7 @@ xmlCatalogXMLResolveURI(xmlCatalogEntryPtr catal, const xmlChar *URI) { } break; case XML_CATA_REWRITE_URI: - len = xmlStrlen(cur->name); + len = xmlStrlenFast(cur->name); if ((len > lenrewrite) && (!xmlStrncmp(URI, cur->name, len))) { lenrewrite = len; @@ -1908,7 +1908,7 @@ xmlCatalogXMLResolveURI(xmlCatalogEntryPtr catal, const xmlChar *URI) { } break; case XML_CATA_DELEGATE_URI: - if (!xmlStrncmp(URI, cur->name, xmlStrlen(cur->name))) + if (!xmlStrncmp(URI, cur->name, xmlStrlenFast(cur->name))) haveDelegate++; break; case XML_CATA_NEXT_CATALOG: @@ -1940,7 +1940,7 @@ xmlCatalogXMLResolveURI(xmlCatalogEntryPtr catal, const xmlChar *URI) { while (cur != NULL) { if (((cur->type == XML_CATA_DELEGATE_SYSTEM) || (cur->type == XML_CATA_DELEGATE_URI)) && - (!xmlStrncmp(URI, cur->name, xmlStrlen(cur->name)))) { + (!xmlStrncmp(URI, cur->name, xmlStrlenFast(cur->name)))) { for (i = 0;i < nbList;i++) if (xmlStrEqual(cur->URL, delegates[i])) break; diff --git a/debugXML.c b/debugXML.c index 3f28c67de..aab8e42e6 100644 --- a/debugXML.c +++ b/debugXML.c @@ -1628,7 +1628,7 @@ xmlLsCountNode(xmlNodePtr node) { case XML_PI_NODE: case XML_COMMENT_NODE: if (node->content != NULL) { - ret = xmlStrlen(node->content); + ret = xmlStrlenFast(node->content); } break; case XML_ENTITY_REF_NODE: diff --git a/entities.c b/entities.c index 37163c195..76990a27a 100644 --- a/entities.c +++ b/entities.c @@ -200,7 +200,7 @@ xmlCreateEntity(xmlDictPtr dict, const xmlChar *name, int type, ret->SystemID = xmlDictLookup(dict, SystemID, -1); } if (content != NULL) { - ret->length = xmlStrlen(content); + ret->length = xmlStrlenFast(content); if ((dict != NULL) && (ret->length < 5)) ret->content = (xmlChar *) xmlDictLookup(dict, content, ret->length); diff --git a/error.c b/error.c index 5f42eadcc..7b5ebe255 100644 --- a/error.c +++ b/error.c @@ -393,7 +393,7 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str, } if (str != NULL) { int len; - len = xmlStrlen((const xmlChar *)str); + len = xmlStrlenFast((const xmlChar *)str); if ((len > 0) && (str[len - 1] != '\n')) channel(data, "%s\n", str); else @@ -414,7 +414,7 @@ xmlReportError(xmlErrorPtr err, xmlParserCtxtPtr ctxt, const char *str, } if ((domain == XML_FROM_XPATH) && (err->str1 != NULL) && (err->int1 < 100) && - (err->int1 < xmlStrlen((const xmlChar *)err->str1))) { + (err->int1 < xmlStrlenFast((const xmlChar *)err->str1))) { xmlChar buf[150]; int i; @@ -775,7 +775,7 @@ xmlParserValidityError(void *ctx, const char *msg, ...) xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserInputPtr input = NULL; char * str; - int len = xmlStrlen((const xmlChar *) msg); + int len = xmlStrlenFast((const xmlChar *) msg); static int had_info = 0; if ((len > 1) && (msg[len - 2] != ':')) { @@ -819,7 +819,7 @@ xmlParserValidityWarning(void *ctx, const char *msg, ...) xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; xmlParserInputPtr input = NULL; char * str; - int len = xmlStrlen((const xmlChar *) msg); + int len = xmlStrlenFast((const xmlChar *) msg); if ((ctxt != NULL) && (len != 0) && (msg[len - 1] != ':')) { input = ctxt->input; diff --git a/libxml.h b/libxml.h index 38afbefbe..cc6c7216e 100644 --- a/libxml.h +++ b/libxml.h @@ -9,6 +9,8 @@ #ifndef __XML_LIBXML_H__ #define __XML_LIBXML_H__ +#include +#include #include #ifndef NO_LARGEFILE_SOURCE @@ -117,6 +119,18 @@ int __xmlRandom(void); XMLPUBFUN xmlChar * XMLCALL xmlEscapeFormatString(xmlChar **msg); int xmlInputReadCallbackNop(void *context, char *buffer, int len); +/* + * Alternative to xmlStrlen that uses POSIX / ISO C standard strlen(). + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-function" +static int +xmlStrlenFast(const xmlChar* str) { + size_t len = str ? strlen((const char *)str) : 0; + return(len > INT_MAX ? 0 : len); +} +#pragma GCC diagnostic pop + #if !defined(PIC) && !defined(NOLIBTOOL) && !defined(LIBXML_STATIC) # define LIBXML_STATIC #endif diff --git a/parser.c b/parser.c index 9978cbe24..2ed92d40c 100644 --- a/parser.c +++ b/parser.c @@ -1330,7 +1330,7 @@ xmlAddDefAttrs(xmlParserCtxtPtr ctxt, defaults->values[5 * defaults->nbAttrs] = name; defaults->values[5 * defaults->nbAttrs + 1] = prefix; /* intern the string and precompute the end */ - len = xmlStrlen(value); + len = xmlStrlenFast(value); value = xmlDictLookup(ctxt->dict, value, len); defaults->values[5 * defaults->nbAttrs + 2] = value; defaults->values[5 * defaults->nbAttrs + 3] = value + len; @@ -2738,7 +2738,7 @@ xmlStringLenDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int len, xmlFree(rep); rep = NULL; } else if (ent != NULL) { - int i = xmlStrlen(ent->name); + int i = xmlStrlenFast(ent->name); const xmlChar *cur = ent->name; buffer[nbchars++] = '&'; @@ -2843,7 +2843,7 @@ xmlChar * xmlStringDecodeEntities(xmlParserCtxtPtr ctxt, const xmlChar *str, int what, xmlChar end, xmlChar end2, xmlChar end3) { if ((ctxt == NULL) || (str == NULL)) return(NULL); - return(xmlStringLenDecodeEntities(ctxt, str, xmlStrlen(str), what, + return(xmlStringLenDecodeEntities(ctxt, str, xmlStrlenFast(str), what, end, end2, end3)); } @@ -4035,7 +4035,7 @@ xmlParseAttValueComplex(xmlParserCtxtPtr ctxt, int *attlen, int normalize) { buf[len++] = ent->content[0]; } } else if (ent != NULL) { - int i = xmlStrlen(ent->name); + int i = xmlStrlenFast(ent->name); const xmlChar *cur = ent->name; /* @@ -7146,7 +7146,7 @@ xmlParseReference(xmlParserCtxtPtr ctxt) { */ if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL) && (!ctxt->disableSAX)) - ctxt->sax->characters(ctxt->userData, val, xmlStrlen(val)); + ctxt->sax->characters(ctxt->userData, val, xmlStrlenFast(val)); return; } @@ -9312,7 +9312,7 @@ xmlParseStartTag2(xmlParserCtxtPtr ctxt, const xmlChar **pref, &aprefix, &attvalue, &len, &alloc); if ((attname == NULL) || (attvalue == NULL)) goto next_attr; - if (len < 0) len = xmlStrlen(attvalue); + if (len < 0) len = xmlStrlenFast(attvalue); if ((attname == ctxt->str_xmlns) && (aprefix == NULL)) { const xmlChar *URL = xmlDictLookup(ctxt->dict, attvalue, len); @@ -13321,7 +13321,7 @@ xmlParseBalancedChunkMemoryInternal(xmlParserCtxtPtr oldctxt, if (string == NULL) return(XML_ERR_INTERNAL_ERROR); - size = xmlStrlen(string); + size = xmlStrlenFast(string); ctxt = xmlCreateMemoryParserCtxt((char *) string, size); if (ctxt == NULL) return(XML_WAR_UNDECLARED_ENTITY); @@ -13744,7 +13744,7 @@ xmlParseBalancedChunkMemoryRecover(xmlDocPtr doc, xmlSAXHandlerPtr sax, if (string == NULL) return(-1); - size = xmlStrlen(string); + size = xmlStrlenFast(string); ctxt = xmlCreateMemoryParserCtxt((char *) string, size); if (ctxt == NULL) return(-1); @@ -14263,7 +14263,7 @@ xmlSetupParserForBuffer(xmlParserCtxtPtr ctxt, const xmlChar* buffer, input->filename = (char *) xmlCanonicPath((const xmlChar *)filename); input->base = buffer; input->cur = buffer; - input->end = &buffer[xmlStrlen(buffer)]; + input->end = &buffer[xmlStrlenFast(buffer)]; inputPush(ctxt, input); } @@ -14540,7 +14540,7 @@ xmlCreateDocParserCtxt(const xmlChar *cur) { if (cur == NULL) return(NULL); - len = xmlStrlen(cur); + len = xmlStrlenFast(cur); return(xmlCreateMemoryParserCtxt((const char *)cur, len)); } diff --git a/parserInternals.c b/parserInternals.c index 270270b22..fd6a3841c 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -1474,7 +1474,7 @@ xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) { input->filename = (char *) xmlStrdup((xmlChar *) entity->URI); input->base = entity->content; if (entity->length == 0) - entity->length = xmlStrlen(entity->content); + entity->length = xmlStrlenFast(entity->content); input->cur = entity->content; input->length = entity->length; input->end = &entity->content[input->length]; @@ -1508,7 +1508,7 @@ xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) { } input->base = buffer; input->cur = buffer; - input->length = xmlStrlen(buffer); + input->length = xmlStrlenFast(buffer); input->end = &buffer[input->length]; return(input); } diff --git a/relaxng.c b/relaxng.c index 312a2c860..c8ab0b8f2 100644 --- a/relaxng.c +++ b/relaxng.c @@ -10597,7 +10597,7 @@ xmlRelaxNGValidateState(xmlRelaxNGValidCtxtPtr ctxt, break; } } - len = xmlStrlen(content); + len = xmlStrlenFast(content); oldvalue = ctxt->state->value; oldendvalue = ctxt->state->endvalue; ctxt->state->value = content; diff --git a/rngparser.c b/rngparser.c index ef3917393..8ceb25d15 100644 --- a/rngparser.c +++ b/rngparser.c @@ -1438,7 +1438,7 @@ xmlConvertCRNG(const char *schemas, int len, const char *encoding) { xmlDocPtr ret = NULL; if (schemas == NULL) return(NULL); - if (len <= 5) len = xmlStrlen((const unsigned char *) schemas); + if (len <= 5) len = xmlStrlenFast((const unsigned char *) schemas); if (len <= 0) return(NULL); memset(&ctxt, 0, sizeof(ctxt)); diff --git a/schematron.c b/schematron.c index d005f56b2..77970a2e4 100644 --- a/schematron.c +++ b/schematron.c @@ -1332,7 +1332,7 @@ xmlSchematronFormatReport(xmlSchematronValidCtxtPtr ctxt, * remove superfluous \n */ if (ret != NULL) { - int len = xmlStrlen(ret); + int len = xmlStrlenFast(ret); xmlChar c; if (len > 0) { diff --git a/tree.c b/tree.c index 32d663397..b8fe7c9b7 100644 --- a/tree.c +++ b/tree.c @@ -2594,7 +2594,7 @@ xmlNewCharRef(xmlDocPtr doc, const xmlChar *name) { if (name[0] == '&') { int len; name++; - len = xmlStrlen(name); + len = xmlStrlenFast(name); if (name[len - 1] == ';') cur->name = xmlStrndup(name, len - 1); else @@ -2638,7 +2638,7 @@ xmlNewReference(const xmlDoc *doc, const xmlChar *name) { if (name[0] == '&') { int len; name++; - len = xmlStrlen(name); + len = xmlStrlenFast(name); if (name[len - 1] == ';') cur->name = xmlStrndup(name, len - 1); else @@ -4910,9 +4910,9 @@ xmlGetNodePath(const xmlNode *node) /* * Make sure there is enough room */ - if (xmlStrlen(buffer) + sizeof(nametemp) + 20 > buf_len) { + if (xmlStrlenFast(buffer) + sizeof(nametemp) + 20 > buf_len) { buf_len = - 2 * buf_len + xmlStrlen(buffer) + sizeof(nametemp) + 20; + 2 * buf_len + xmlStrlenFast(buffer) + sizeof(nametemp) + 20; temp = (xmlChar *) xmlRealloc(buffer, buf_len); if (temp == NULL) { xmlTreeErrMemory("getting node path"); @@ -5915,7 +5915,7 @@ xmlNodeAddContent(xmlNodePtr cur, const xmlChar *content) { return; } if (content == NULL) return; - len = xmlStrlen(content); + len = xmlStrlenFast(content); xmlNodeAddContentLen(cur, content, len); } @@ -7575,7 +7575,7 @@ xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len) { if (len == 0) return 0; if (len < 0) - len = xmlStrlen(str); + len = xmlStrlenFast(str); if (len < 0) return -1; if (len == 0) return 0; @@ -7630,7 +7630,7 @@ xmlBufferAddHead(xmlBufferPtr buf, const xmlChar *str, int len) { if (len == 0) return 0; if (len < 0) - len = xmlStrlen(str); + len = xmlStrlenFast(str); if (len <= 0) return -1; diff --git a/uri.c b/uri.c index 81ec7f432..2cdbaba34 100644 --- a/uri.c +++ b/uri.c @@ -1686,7 +1686,7 @@ xmlURIEscapeStr(const xmlChar *str, const xmlChar *list) { return(NULL); if (str[0] == 0) return(xmlStrdup(str)); - len = xmlStrlen(str); + len = xmlStrlenFast(str); if (!(len > 0)) return(NULL); len += 20; @@ -2295,7 +2295,7 @@ xmlBuildRelativeURI (const xmlChar * URI, const xmlChar * base) goto done; } - len = xmlStrlen (uptr) + 1; + len = xmlStrlenFast (uptr) + 1; } if (nbslash == 0) { @@ -2464,7 +2464,7 @@ path_processing: return(NULL); } - len = xmlStrlen(path); + len = xmlStrlenFast(path); if ((len > 2) && IS_WINDOWS_PATH(path)) { /* make the scheme 'file' */ uri->scheme = (char *) xmlStrdup(BAD_CAST "file"); diff --git a/valid.c b/valid.c index d1df2d506..a7dd6df9f 100644 --- a/valid.c +++ b/valid.c @@ -1334,10 +1334,10 @@ xmlSnprintfElementContent(char *buf, int size, xmlElementContentPtr content, int strcat(buf, "#PCDATA"); break; case XML_ELEMENT_CONTENT_ELEMENT: { - int qnameLen = xmlStrlen(content->name); + int qnameLen = xmlStrlenFast(content->name); if (content->prefix != NULL) - qnameLen += xmlStrlen(content->prefix) + 1; + qnameLen += xmlStrlenFast(content->prefix) + 1; if (size - len < qnameLen + 10) { strcat(buf, " ..."); return; @@ -5257,7 +5257,7 @@ xmlSnprintfElements(char *buf, int size, xmlNodePtr node, int glob) { switch (cur->type) { case XML_ELEMENT_NODE: if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { - if (size - len < xmlStrlen(cur->ns->prefix) + 10) { + if (size - len < xmlStrlenFast(cur->ns->prefix) + 10) { if ((size - len > 4) && (buf[len - 1] != '.')) strcat(buf, " ..."); return; @@ -5265,7 +5265,7 @@ xmlSnprintfElements(char *buf, int size, xmlNodePtr node, int glob) { strcat(buf, (char *) cur->ns->prefix); strcat(buf, ":"); } - if (size - len < xmlStrlen(cur->name) + 10) { + if (size - len < xmlStrlenFast(cur->name) + 10) { if ((size - len > 4) && (buf[len - 1] != '.')) strcat(buf, " ..."); return; diff --git a/xmlreader.c b/xmlreader.c index be3f6610b..78a1f9dfa 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -1057,7 +1057,7 @@ xmlTextReaderValidateEntity(xmlTextReaderPtr reader) { } else if ((node->type == XML_TEXT_NODE) || (node->type == XML_CDATA_SECTION_NODE)) { xmlTextReaderValidateCData(reader, node->content, - xmlStrlen(node->content)); + xmlStrlenFast(node->content)); #endif } @@ -1514,7 +1514,7 @@ node_found: } else if ((node->type == XML_TEXT_NODE) || (node->type == XML_CDATA_SECTION_NODE)) { xmlTextReaderValidateCData(reader, node->content, - xmlStrlen(node->content)); + xmlStrlenFast(node->content)); } } #endif /* LIBXML_REGEXP_ENABLED */ @@ -4828,7 +4828,7 @@ xmlTextReaderValidityError(void *ctxt, const char *msg, ...) { va_list ap; - int len = xmlStrlen((const xmlChar *) msg); + int len = xmlStrlenFast((const xmlChar *) msg); if ((len > 1) && (msg[len - 2] != ':')) { /* @@ -4848,7 +4848,7 @@ xmlTextReaderValidityWarning(void *ctxt, const char *msg, ...) { va_list ap; - int len = xmlStrlen((const xmlChar *) msg); + int len = xmlStrlenFast((const xmlChar *) msg); if ((len != 0) && (msg[len - 1] != ':')) { /* @@ -5328,7 +5328,7 @@ xmlReaderForDoc(const xmlChar * cur, const char *URL, const char *encoding, if (cur == NULL) return (NULL); - len = xmlStrlen(cur); + len = xmlStrlenFast(cur); return (xmlReaderForMemory ((const char *) cur, len, URL, encoding, options)); @@ -5541,7 +5541,7 @@ xmlReaderNewDoc(xmlTextReaderPtr reader, const xmlChar * cur, if (reader == NULL) return (-1); - len = xmlStrlen(cur); + len = xmlStrlenFast(cur); return (xmlReaderNewMemory(reader, (const char *)cur, len, URL, encoding, options)); } diff --git a/xmlsave.c b/xmlsave.c index 3addd6528..f38fddadb 100644 --- a/xmlsave.c +++ b/xmlsave.c @@ -335,7 +335,7 @@ xmlSaveCtxtInit(xmlSaveCtxtPtr ctxt) if (ctxt == NULL) return; if ((ctxt->encoding == NULL) && (ctxt->escape == NULL)) ctxt->escape = xmlEscapeEntities; - len = xmlStrlen((xmlChar *)xmlTreeIndentString); + len = xmlStrlenFast((xmlChar *)xmlTreeIndentString); if ((xmlTreeIndentString == NULL) || (len == 0)) { memset(&ctxt->indent[0], 0, MAX_INDENT + 1); } else { @@ -445,7 +445,7 @@ xmlAttrSerializeContent(xmlOutputBufferPtr buf, xmlAttrPtr attr) case XML_ENTITY_REF_NODE: xmlBufAdd(buf->buffer, BAD_CAST "&", 1); xmlBufAdd(buf->buffer, children->name, - xmlStrlen(children->name)); + xmlStrlenFast(children->name)); xmlBufAdd(buf->buffer, BAD_CAST ";", 1); break; default: diff --git a/xmlschemas.c b/xmlschemas.c index 493db3461..0671a01e2 100644 --- a/xmlschemas.c +++ b/xmlschemas.c @@ -1553,7 +1553,7 @@ xmlSchemaGetCanonValueWhtspExt_1(xmlSchemaValPtr val, the same hash value for this to work, and it's easiest to just cut off the useless '.0' suffix for the decimal type. */ - int len = xmlStrlen(value2); + int len = xmlStrlenFast(value2); if (len > 2 && value2[len-1] == '0' && value2[len-2] == '.') ((xmlChar*)value2)[len-2] = 0; } @@ -27042,7 +27042,7 @@ xmlSchemaVPushText(xmlSchemaValidCtxtPtr vctxt, } } else { if (len < 0) - len = xmlStrlen(value); + len = xmlStrlenFast(value); /* * Concat the value. */ diff --git a/xmlstring.c b/xmlstring.c index a85685d7e..807316db8 100644 --- a/xmlstring.c +++ b/xmlstring.c @@ -347,7 +347,7 @@ xmlStrstr(const xmlChar *str, const xmlChar *val) { if (str == NULL) return(NULL); if (val == NULL) return(NULL); - n = xmlStrlen(val); + n = xmlStrlenFast(val); if (n == 0) return(str); while (*str != 0) { /* non input consuming */ @@ -375,7 +375,7 @@ xmlStrcasestr(const xmlChar *str, const xmlChar *val) { if (str == NULL) return(NULL); if (val == NULL) return(NULL); - n = xmlStrlen(val); + n = xmlStrlenFast(val); if (n == 0) return(str); while (*str != 0) { /* non input consuming */ @@ -460,7 +460,7 @@ xmlStrncat(xmlChar *cur, const xmlChar *add, int len) { if (cur == NULL) return(xmlStrndup(add, len)); - size = xmlStrlen(cur); + size = xmlStrlenFast(cur); if ((size < 0) || (size > INT_MAX - len)) return(NULL); ret = (xmlChar *) xmlRealloc(cur, ((size_t) size + len + 1) * sizeof(xmlChar)); @@ -491,7 +491,7 @@ xmlStrncatNew(const xmlChar *str1, const xmlChar *str2, int len) { xmlChar *ret; if (len < 0) { - len = xmlStrlen(str2); + len = xmlStrlenFast(str2); if (len < 0) return(NULL); } @@ -500,7 +500,7 @@ xmlStrncatNew(const xmlChar *str1, const xmlChar *str2, int len) { if (str1 == NULL) return(xmlStrndup(str2, len)); - size = xmlStrlen(str1); + size = xmlStrlenFast(str1); if ((size < 0) || (size > INT_MAX - len)) return(NULL); ret = (xmlChar *) xmlMalloc(((size_t) size + len + 1) * sizeof(xmlChar)); diff --git a/xmlwriter.c b/xmlwriter.c index 2ca2056e2..1be69afcd 100644 --- a/xmlwriter.c +++ b/xmlwriter.c @@ -1404,7 +1404,7 @@ xmlTextWriterWriteRawLen(xmlTextWriterPtr writer, const xmlChar * content, int xmlTextWriterWriteRaw(xmlTextWriterPtr writer, const xmlChar * content) { - return xmlTextWriterWriteRawLen(writer, content, xmlStrlen(content)); + return xmlTextWriterWriteRawLen(writer, content, xmlStrlenFast(content)); } /** diff --git a/xpath.c b/xpath.c index 11b452e57..717636816 100644 --- a/xpath.c +++ b/xpath.c @@ -5991,7 +5991,7 @@ xmlXPathCastNumberToBoolean (double val) { */ int xmlXPathCastStringToBoolean (const xmlChar *val) { - if ((val == NULL) || (xmlStrlen(val) == 0)) + if ((val == NULL) || (xmlStrlenFast(val) == 0)) return(0); return(1); } @@ -9051,7 +9051,7 @@ xmlXPathStartsWithFunction(xmlXPathParserContextPtr ctxt, int nargs) { xmlXPathReleaseObject(ctxt->context, needle); XP_ERROR(XPATH_INVALID_TYPE); } - n = xmlStrlen(needle->stringval); + n = xmlStrlenFast(needle->stringval); if (xmlStrncmp(hay->stringval, needle->stringval, n)) valuePush(ctxt, xmlXPathCacheNewBoolean(ctxt->context, 0)); else @@ -9232,9 +9232,9 @@ xmlXPathSubstringAfterFunction(xmlXPathParserContextPtr ctxt, int nargs) { if (target) { point = xmlStrstr(str->stringval, find->stringval); if (point) { - offset = (int)(point - str->stringval) + xmlStrlen(find->stringval); + offset = (int)(point - str->stringval) + xmlStrlenFast(find->stringval); xmlBufAdd(target, &str->stringval[offset], - xmlStrlen(str->stringval) - offset); + xmlStrlenFast(str->stringval) - offset); } valuePush(ctxt, xmlXPathCacheNewString(ctxt->context, xmlBufContent(target))); @@ -10595,7 +10595,7 @@ xmlXPathCompPathExpr(xmlXPathParserContextPtr ctxt) { lc = 1; xmlFree(name); } else if (name != NULL) { - int len =xmlStrlen(name); + int len =xmlStrlenFast(name); while (NXT(len) != 0) { @@ -13995,7 +13995,7 @@ xmlXPathEvalPredicate(xmlXPathContextPtr ctxt, xmlXPathObjectPtr res) { return(res->nodesetval->nodeNr != 0); case XPATH_STRING: return((res->stringval != NULL) && - (xmlStrlen(res->stringval) != 0)); + (xmlStrlenFast(res->stringval) != 0)); default: STRANGE } diff --git a/xpointer.c b/xpointer.c index d6728896b..38fb6f91d 100644 --- a/xpointer.c +++ b/xpointer.c @@ -961,7 +961,7 @@ xmlXPtrEvalXPtrPart(xmlXPathParserContextPtr ctxt, xmlChar *name) { NEXT; level = 1; - len = xmlStrlen(ctxt->cur); + len = xmlStrlenFast(ctxt->cur); len++; buffer = (xmlChar *) xmlMallocAtomic(len * sizeof (xmlChar)); if (buffer == NULL) { @@ -1694,7 +1694,7 @@ xmlXPtrNbLocChildren(xmlNodePtr node) { case XML_TEXT_NODE: case XML_CDATA_SECTION_NODE: case XML_ENTITY_REF_NODE: - ret = xmlStrlen(node->content); + ret = xmlStrlenFast(node->content); break; default: return(-1); @@ -2086,7 +2086,7 @@ xmlXPtrInsideRange(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr loc) { return(xmlXPtrNewRange(node, 0, node, 0)); } else { return(xmlXPtrNewRange(node, 0, node, - xmlStrlen(node->content))); + xmlStrlenFast(node->content))); } } case XML_ATTRIBUTE_NODE: @@ -2118,7 +2118,7 @@ xmlXPtrInsideRange(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr loc) { return(xmlXPtrNewRange(node, 0, node, 0)); } else { return(xmlXPtrNewRange(node, 0, node, - xmlStrlen(node->content))); + xmlStrlenFast(node->content))); } } case XML_ATTRIBUTE_NODE: @@ -2342,7 +2342,7 @@ xmlXPtrAdvanceChar(xmlNodePtr *node, int *indx, int bytes) { len = 0; if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) { - len = xmlStrlen(cur->content); + len = xmlStrlenFast(cur->content); } if (pos > len) { /* Strange, the indx in the text node is greater than it's len */ @@ -2397,14 +2397,14 @@ xmlXPtrMatchString(const xmlChar *string, xmlNodePtr start, int startindex, return(-1); cur = start; pos = startindex - 1; - stringlen = xmlStrlen(string); + stringlen = xmlStrlenFast(string); while (stringlen > 0) { if ((cur == *end) && (pos + stringlen > *endindex)) return(0); if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) { - len = xmlStrlen(cur->content); + len = xmlStrlenFast(cur->content); if (len >= pos + stringlen) { match = (!xmlStrncmp(&cur->content[pos], string, stringlen)); if (match) { @@ -2485,7 +2485,7 @@ xmlXPtrSearchString(const xmlChar *string, xmlNodePtr *start, int *startindex, while (cur != NULL) { if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) { - len = xmlStrlen(cur->content); + len = xmlStrlenFast(cur->content); while (pos <= len) { if (first != 0) { str = xmlStrchr(&cur->content[pos], first); @@ -2571,7 +2571,7 @@ xmlXPtrGetLastChar(xmlNodePtr *node, int *indx) { cur = cur->last; else if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) { - len = xmlStrlen(cur->content); + len = xmlStrlenFast(cur->content); break; } else { return(-1); -- GitLab