From 4fd156c45f4875aad3a12123e67082de33908bc4 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 16 May 2014 08:48:40 +0200 Subject: [PATCH] strbuf utils: Fixed resizing in append. Previously, resizing happened "too early" which may possibly generate avoidable memory churn. --- src/utils/strbuf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } -- 2.30.2