From 5bf95e9a4dcd2c02df7ff5317ea810820c442074 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 10 Dec 2018 04:06:19 +0100 Subject: xplist: Prevent unnecessary reallocations when writing XML output --- src/xplist.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/xplist.c b/src/xplist.c index 29b1284..739b5ab 100644 --- a/src/xplist.c +++ b/src/xplist.c @@ -293,7 +293,10 @@ static void node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth) uint32_t maxread = ((76 - indent*8) / 4) * 3; size_t count = 0; size_t b64count = 0; - str_buf_grow(*outbuf, (node_data->length / 3 * 4) + 4 + (((node_data->length / maxread) + 1) * (indent+1))); + size_t amount = (node_data->length / 3 * 4) + 4 + (((node_data->length / maxread) + 1) * (indent+1)); + if ((*outbuf)->len + amount > (*outbuf)->capacity) { + str_buf_grow(*outbuf, amount); + } while (j < node_data->length) { for (i = 0; i < indent; i++) { str_buf_append(*outbuf, "\t", 1); -- cgit v1.1-32-gdbae