From: Sebastian Harl Date: Fri, 16 May 2014 06:48:40 +0000 (+0200) Subject: strbuf utils: Fixed resizing in append. X-Git-Tag: sysdb-0.1.0~15 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4fd156c45f4875aad3a12123e67082de33908bc4;p=sysdb.git strbuf utils: Fixed resizing in append. Previously, resizing happened "too early" which may possibly generate avoidable memory churn. --- diff --git a/src/utils/strbuf.c b/src/utils/strbuf.c index 6c881be..0474677 100644 --- a/src/utils/strbuf.c +++ b/src/utils/strbuf.c @@ -154,8 +154,8 @@ sdb_strbuf_vappend(sdb_strbuf_t *strbuf, const char *fmt, va_list ap) } /* 'status' does not include nul-byte */ - if ((size_t)status >= strbuf->size - strbuf->pos - 1) { - if (strbuf_resize(strbuf, strbuf->size + (size_t)status + 1)) { + if ((size_t)status >= strbuf->size - strbuf->pos) { + if (strbuf_resize(strbuf, strbuf->pos + (size_t)status + 1)) { va_end(aq); return -1; }