From: NeilBrown Date: Tue, 1 Dec 2015 20:43:18 +0000 (+1100) Subject: text: fix bug with adding at end of allocation. X-Git-Tag: lca2016~148 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=638d8af4e978c7c7306529457cd2084c75c8ff83;p=edlib.git text: fix bug with adding at end of allocation. Signed-off-by: NeilBrown --- diff --git a/doc-text.c b/doc-text.c index 2b8550ec..930b22d4 100644 --- a/doc-text.c +++ b/doc-text.c @@ -353,15 +353,18 @@ static void text_add_str(struct text *t, struct doc_ref *pos, char *str, */ struct text_alloc *a = t->alloc; int len = strlen(str); + int len2; if (start) *start = *pos; + len2 = len; if (pos->c && pos->o == pos->c->end && pos->c->txt + pos->o == a->text + a->free && (a->size - a->free >= len || - (len = text_round_len(str, a->size - a->free)) > 0)) { + (len2 = text_round_len(str, a->size - a->free)) > 0)) { /* Some of this ('len') can be added to the current chunk */ + len = len2; memcpy(a->text+a->free, str, len); a->free += len; pos->c->end += len;