MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlParseStringName

Function xmlParseStringName

ThirdParty/libxml2/vtklibxml2/parser.c:3573–3646  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3571 */
3572
3573static xmlChar *
3574xmlParseStringName(xmlParserCtxtPtr ctxt, const xmlChar** str) {
3575 xmlChar buf[XML_MAX_NAMELEN + 5];
3576 xmlChar *ret;
3577 const xmlChar *cur = *str;
3578 int len = 0, l;
3579 int c;
3580 int maxLength = (ctxt->options & XML_PARSE_HUGE) ?
3581 XML_MAX_TEXT_LENGTH :
3582 XML_MAX_NAME_LENGTH;
3583
3584 c = CUR_SCHAR(cur, l);
3585 if (!xmlIsNameStartChar(ctxt, c)) {
3586 return(NULL);
3587 }
3588
3589 COPY_BUF(buf, len, c);
3590 cur += l;
3591 c = CUR_SCHAR(cur, l);
3592 while (xmlIsNameChar(ctxt, c)) {
3593 COPY_BUF(buf, len, c);
3594 cur += l;
3595 c = CUR_SCHAR(cur, l);
3596 if (len >= XML_MAX_NAMELEN) { /* test bigentname.xml */
3597 /*
3598 * Okay someone managed to make a huge name, so he's ready to pay
3599 * for the processing speed.
3600 */
3601 xmlChar *buffer;
3602 int max = len * 2;
3603
3604 buffer = (xmlChar *) xmlMallocAtomic(max);
3605 if (buffer == NULL) {
3606 xmlErrMemory(ctxt);
3607 return(NULL);
3608 }
3609 memcpy(buffer, buf, len);
3610 while (xmlIsNameChar(ctxt, c)) {
3611 if (len + 10 > max) {
3612 xmlChar *tmp;
3613
3614 max *= 2;
3615 tmp = (xmlChar *) xmlRealloc(buffer, max);
3616 if (tmp == NULL) {
3617 xmlErrMemory(ctxt);
3618 xmlFree(buffer);
3619 return(NULL);
3620 }
3621 buffer = tmp;
3622 }
3623 COPY_BUF(buffer, len, c);
3624 cur += l;
3625 c = CUR_SCHAR(cur, l);
3626 if (len > maxLength) {
3627 xmlFatalErr(ctxt, XML_ERR_NAME_TOO_LONG, "NCName");
3628 xmlFree(buffer);
3629 return(NULL);
3630 }

Callers 3

xmlParseStringEntityRefFunction · 0.85

Calls 5

xmlIsNameStartCharFunction · 0.85
xmlIsNameCharFunction · 0.85
xmlErrMemoryFunction · 0.85
xmlFatalErrFunction · 0.85
xmlStrndupFunction · 0.85

Tested by

no test coverage detected