X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fwrbuf.c;h=e57aab7699ea4f563949daeab8aa7f24a106e355;hb=0a479be82be90639f4e37c4ead12baca543e88bf;hp=7015bade5050c23e39e065ad45f3a02450f86b12;hpb=97fafedd350b74076d8a8e31e23102fa22d4b430;p=yaz-moved-to-github.git diff --git a/src/wrbuf.c b/src/wrbuf.c index 7015bad..e57aab7 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,18 @@ 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; +} + +const char *wrbuf_cstr_null(WRBUF b) +{ + if (!b || b->pos == 0) + return 0; + assert(b->pos < b->size); b->buf[b->pos] = '\0'; return b->buf; }