* xmlParserShrink: * @ctxt: an XML parser context * * Shrink the input buffer. */
| 533 | * Shrink the input buffer. |
| 534 | */ |
| 535 | void |
| 536 | xmlParserShrink(xmlParserCtxtPtr ctxt) { |
| 537 | xmlParserInputPtr in = ctxt->input; |
| 538 | xmlParserInputBufferPtr buf = in->buf; |
| 539 | size_t used; |
| 540 | |
| 541 | if (buf == NULL) |
| 542 | return; |
| 543 | /* Don't shrink pull parser memory buffers. */ |
| 544 | if ((!PARSER_PROGRESSIVE(ctxt)) && |
| 545 | (buf->encoder == NULL) && |
| 546 | (buf->readcallback == NULL)) |
| 547 | return; |
| 548 | |
| 549 | used = in->cur - in->base; |
| 550 | /* |
| 551 | * Do not shrink on large buffers whose only a tiny fraction |
| 552 | * was consumed |
| 553 | */ |
| 554 | if (used > INPUT_CHUNK) { |
| 555 | size_t res = xmlBufShrink(buf->buffer, used - LINE_LEN); |
| 556 | |
| 557 | if (res > 0) { |
| 558 | used -= res; |
| 559 | if ((res > ULONG_MAX) || |
| 560 | (in->consumed > ULONG_MAX - (unsigned long)res)) |
| 561 | in->consumed = ULONG_MAX; |
| 562 | else |
| 563 | in->consumed += res; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | xmlBufUpdateInput(buf->buffer, in, used); |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * xmlParserInputShrink: |
no test coverage detected