From: Alexandre Oliva Date: Thu, 6 Mar 2014 16:17:12 +0000 (-0300) Subject: Grow message by just the needed amount X-Git-Tag: v2014.1~18 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Flibreceita.git;a=commitdiff_plain;h=9b15de84f1628712b63134c70392a770fa021068 Grow message by just the needed amount Do not allocate more space than required for the message to grow. We used to nearly double the amount of space every time, which is nice to avoid quadratic complexity, but files are small enough that it probably doesn't matter much, and it just makes things confusing. --- diff --git a/decfile.c b/decfile.c index bfaf1ee..f300d69 100644 --- a/decfile.c +++ b/decfile.c @@ -430,13 +430,15 @@ static int append_stripped_reg_ctrl(struct rnet_message **message, char *line) { size_t len; struct rnet_message *msg = *message; + int growth; if (!decfile_reg_is_dec(line)) return 0; len = strlen(line); if (len < 12) return -EINVAL; - if (msg->alen - msg->len < len) { - if (rnet_message_expand(message, MAX(msg->len, len))) + growth = msg->len + len - 10 - msg->alen; + if (growth > 0) { + if (rnet_message_expand(message, growth)) return -ENOMEM; msg = *message; }