X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fwrbuf.c;h=3c631704dfce0e63a736d236a1efc343e5be0099;hp=972acffcc47680207e62b4a2da89387aca23d50b;hb=7d640b3f9eeb46ab57958aa21b63f26271162ee7;hpb=473824797f568578dc17d7242551cb2f7ccef46c diff --git a/src/wrbuf.c b/src/wrbuf.c index 972acff..3c63170 100644 --- a/src/wrbuf.c +++ b/src/wrbuf.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -69,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; } @@ -79,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; @@ -262,8 +263,10 @@ void wrbuf_iconv_reset(WRBUF b, yaz_iconv_t cd) const char *wrbuf_cstr(WRBUF b) { - wrbuf_putc(b, '\0'); /* add '\0' */ - (b->pos)--; /* don't include '\0' in count */ + if (b->pos == 0) + return ""; + assert(b->pos < b->size); + b->buf[b->pos] = '\0'; return b->buf; }