* xmlBufferResize: * @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 */
| 7424 | * Returns 0 in case of problems, 1 otherwise |
| 7425 | */ |
| 7426 | int |
| 7427 | xmlBufferResize(xmlBufferPtr buf, unsigned int size) |
| 7428 | { |
| 7429 | unsigned int newSize; |
| 7430 | xmlChar* rebuf = NULL; |
| 7431 | size_t start_buf; |
| 7432 | |
| 7433 | if (buf == NULL) |
| 7434 | return(0); |
| 7435 | |
| 7436 | /* Don't resize if we don't have to */ |
| 7437 | if (size < buf->size) |
| 7438 | return 1; |
| 7439 | |
| 7440 | if (size > UINT_MAX - 10) |
| 7441 | return 0; |
| 7442 | |
| 7443 | /* figure out new size */ |
| 7444 | switch (buf->alloc){ |
| 7445 | case XML_BUFFER_ALLOC_IO: |
| 7446 | case XML_BUFFER_ALLOC_DOUBLEIT: |
| 7447 | /*take care of empty case*/ |
| 7448 | if (buf->size == 0) |
| 7449 | newSize = size + 10; |
| 7450 | else |
| 7451 | newSize = buf->size; |
| 7452 | while (size > newSize) { |
| 7453 | if (newSize > UINT_MAX / 2) |
| 7454 | return 0; |
| 7455 | newSize *= 2; |
| 7456 | } |
| 7457 | break; |
| 7458 | case XML_BUFFER_ALLOC_EXACT: |
| 7459 | newSize = size + 10; |
| 7460 | break; |
| 7461 | case XML_BUFFER_ALLOC_HYBRID: |
| 7462 | if (buf->use < BASE_BUFFER_SIZE) |
| 7463 | newSize = size; |
| 7464 | else { |
| 7465 | newSize = buf->size; |
| 7466 | while (size > newSize) { |
| 7467 | if (newSize > UINT_MAX / 2) |
| 7468 | return 0; |
| 7469 | newSize *= 2; |
| 7470 | } |
| 7471 | } |
| 7472 | break; |
| 7473 | |
| 7474 | default: |
| 7475 | newSize = size + 10; |
| 7476 | break; |
| 7477 | } |
| 7478 | |
| 7479 | if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { |
| 7480 | start_buf = buf->content - buf->contentIO; |
| 7481 | |
| 7482 | if (start_buf > newSize) { |
| 7483 | /* move data back to start */ |
no outgoing calls
no test coverage detected