#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+#include <assert.h>
#include <yaz/wrbuf.h>
#include <yaz/snprintf.h>
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;
}
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;
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;
}