X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fwrbuf.c;h=3c631704dfce0e63a736d236a1efc343e5be0099;hp=344e5742cc00e71ba8d6ad8a1deff7892e918724;hb=7d640b3f9eeb46ab57958aa21b63f26271162ee7;hpb=e529ed18a6825f980bb16b230e56c6d53743ced1 diff --git a/src/wrbuf.c b/src/wrbuf.c index 344e574..3c63170 100644 --- a/src/wrbuf.c +++ b/src/wrbuf.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2013 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ @@ -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; }