From 1c8eaf558e17a0ef7de91a4e21a0b83683b3dfd7 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 8 Apr 2014 14:18:04 +0200 Subject: [PATCH] wrbuf_cstr: ensure wrbuf_grow is never called YAZ-753 We just throw an assert instead, but that's never going to happen. --- src/wrbuf.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wrbuf.c b/src/wrbuf.c index 7015bad..3c63170 100644 --- a/src/wrbuf.c +++ b/src/wrbuf.c @@ -70,7 +70,7 @@ void wrbuf_write(WRBUF b, const char *buf, size_t size) if (size <= 0) return; if (b->pos + size >= b->size) - wrbuf_grow(b, size); + wrbuf_grow(b, size + 1); memcpy(b->buf + b->pos, buf, size); b->pos += size; } @@ -80,7 +80,7 @@ void wrbuf_insert(WRBUF b, size_t pos, const char *buf, size_t size) if (size <= 0 || pos > b->pos) return; if (b->pos + size >= b->size) - wrbuf_grow(b, size); + wrbuf_grow(b, size + 1); memmove(b->buf + pos + size, b->buf + pos, b->pos - pos); memcpy(b->buf + pos, buf, size); b->pos += size; @@ -263,8 +263,9 @@ void wrbuf_iconv_reset(WRBUF b, yaz_iconv_t cd) const char *wrbuf_cstr(WRBUF b) { - if (b->pos >= b->size) - wrbuf_grow(b, 1); + if (b->pos == 0) + return ""; + assert(b->pos < b->size); b->buf[b->pos] = '\0'; return b->buf; } -- 1.7.10.4