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

Function xmlBufAdd

ThirdParty/libxml2/vtklibxml2/buf.c:756–800  ·  view source on GitHub ↗

* xmlBufAdd: * @buf: the buffer to dump * @str: the #xmlChar string * @len: the number of #xmlChar to add * * Add a string range to an XML buffer. if len == -1, the length of * str is recomputed. * * Returns 0 if successful, -1 in case of error. */

Source from the content-addressed store, hash-verified

754 * Returns 0 if successful, -1 in case of error.
755 */
756int
757xmlBufAdd(xmlBufPtr buf, const xmlChar *str, int len) {
758 size_t needSize;
759
760 if ((str == NULL) || (buf == NULL) || (buf->error))
761 return -1;
762 CHECK_COMPAT(buf)
763
764 if (len < -1) {
765 return -1;
766 }
767 if (len == 0) return 0;
768
769 if (len < 0)
770 len = xmlStrlen(str);
771
772 if (len < 0) return -1;
773 if (len == 0) return 0;
774
775 /* Note that both buf->size and buf->use can be zero here. */
776 if ((size_t) len >= buf->size - buf->use) {
777 if ((size_t) len >= SIZE_MAX - buf->use) {
778 xmlBufMemoryError(buf);
779 return(-1);
780 }
781 needSize = buf->use + len + 1;
782 if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {
783 /*
784 * Used to provide parsing limits
785 */
786 if (needSize >= XML_MAX_TEXT_LENGTH) {
787 xmlBufMemoryError(buf);
788 return(-1);
789 }
790 }
791 if (!xmlBufResize(buf, needSize))
792 return(-1);
793 }
794
795 memmove(&buf->content[buf->use], str, len);
796 buf->use += len;
797 buf->content[buf->use] = 0;
798 UPDATE_COMPAT(buf)
799 return 0;
800}
801
802/**
803 * xmlBufCat:

Callers 7

xmlBufCatFunction · 0.85
xmlParserInputBufferPushFunction · 0.85
xmlOutputBufferWriteFunction · 0.85

Calls 3

xmlStrlenFunction · 0.85
xmlBufMemoryErrorFunction · 0.85
xmlBufResizeFunction · 0.85

Tested by

no test coverage detected