From: Adam Dickmeiss Date: Tue, 8 Apr 2014 12:18:04 +0000 (+0200) Subject: wrbuf_cstr: ensure wrbuf_grow is never called YAZ-753 X-Git-Tag: v5.0.22~2 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=1c8eaf558e17a0ef7de91a4e21a0b83683b3dfd7 wrbuf_cstr: ensure wrbuf_grow is never called YAZ-753 We just throw an assert instead, but that's never going to happen. --- 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; }