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.
{
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;
}