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

Function xmlBufferGrow

ThirdParty/libxml2/vtklibxml2/tree.c:7320–7355  ·  view source on GitHub ↗

* xmlBufferGrow: * @buf: the buffer * @len: the minimum free size to allocate * * Grow the available space of an XML buffer. * * Returns the new available space or -1 in case of error */

Source from the content-addressed store, hash-verified

7318 * Returns the new available space or -1 in case of error
7319 */
7320int
7321xmlBufferGrow(xmlBufferPtr buf, unsigned int len) {
7322 unsigned int size;
7323 xmlChar *newbuf;
7324
7325 if (buf == NULL) return(-1);
7326
7327 if (len < buf->size - buf->use)
7328 return(0);
7329 if (len >= UINT_MAX - buf->use)
7330 return(-1);
7331
7332 if (buf->size > (size_t) len) {
7333 size = buf->size > UINT_MAX / 2 ? UINT_MAX : buf->size * 2;
7334 } else {
7335 size = buf->use + len;
7336 size = size > UINT_MAX - 100 ? UINT_MAX : size + 100;
7337 }
7338
7339 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) {
7340 size_t start_buf = buf->content - buf->contentIO;
7341
7342 newbuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + size);
7343 if (newbuf == NULL)
7344 return(-1);
7345 buf->contentIO = newbuf;
7346 buf->content = newbuf + start_buf;
7347 } else {
7348 newbuf = (xmlChar *) xmlRealloc(buf->content, size);
7349 if (newbuf == NULL)
7350 return(-1);
7351 buf->content = newbuf;
7352 }
7353 buf->size = size;
7354 return(buf->size - buf->use - 1);
7355}
7356
7357/**
7358 * xmlBufferDump:

Callers 2

xmlCharEncInFuncFunction · 0.85
xmlCharEncOutFuncFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected