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

Function xmlBufResize

ThirdParty/libxml2/vtklibxml2/buf.c:628–743  ·  view source on GitHub ↗

* xmlBufResize: * @buf: the buffer to resize * @size: the desired size * * Resize a buffer to accommodate minimum size of @size. * * Returns 0 in case of problems, 1 otherwise */

Source from the content-addressed store, hash-verified

626 * Returns 0 in case of problems, 1 otherwise
627 */
628int
629xmlBufResize(xmlBufPtr buf, size_t size)
630{
631 size_t newSize;
632 xmlChar* rebuf = NULL;
633 size_t start_buf;
634
635 if ((buf == NULL) || (buf->error))
636 return(0);
637 CHECK_COMPAT(buf)
638
639 if (buf->alloc == XML_BUFFER_ALLOC_BOUNDED) {
640 /*
641 * Used to provide parsing limits
642 */
643 if (size >= XML_MAX_TEXT_LENGTH) {
644 xmlBufMemoryError(buf);
645 return(0);
646 }
647 }
648
649 /* Don't resize if we don't have to */
650 if (size < buf->size)
651 return 1;
652
653 /* figure out new size */
654 switch (buf->alloc){
655 case XML_BUFFER_ALLOC_IO:
656 case XML_BUFFER_ALLOC_DOUBLEIT:
657 /*take care of empty case*/
658 if (buf->size == 0) {
659 newSize = (size > SIZE_MAX - 10 ? SIZE_MAX : size + 10);
660 } else {
661 newSize = buf->size;
662 }
663 while (size > newSize) {
664 if (newSize > SIZE_MAX / 2) {
665 xmlBufMemoryError(buf);
666 return 0;
667 }
668 newSize *= 2;
669 }
670 break;
671 case XML_BUFFER_ALLOC_EXACT:
672 newSize = (size > SIZE_MAX - 10 ? SIZE_MAX : size + 10);
673 break;
674 case XML_BUFFER_ALLOC_HYBRID:
675 if (buf->use < BASE_BUFFER_SIZE)
676 newSize = size;
677 else {
678 newSize = buf->size;
679 while (size > newSize) {
680 if (newSize > SIZE_MAX / 2) {
681 xmlBufMemoryError(buf);
682 return 0;
683 }
684 newSize *= 2;
685 }

Callers 1

xmlBufAddFunction · 0.85

Calls 1

xmlBufMemoryErrorFunction · 0.85

Tested by

no test coverage detected