From: Heikki Levanto Date: Tue, 8 Apr 2014 11:44:58 +0000 (+0200) Subject: wrbuf_cstr bit more thread safe YAZ-753 X-Git-Tag: v5.0.22~3 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=97fafedd350b74076d8a8e31e23102fa22d4b430 wrbuf_cstr bit more thread safe YAZ-753 Now it does not mess with the pos. Still not 100% safe, can have a race condition when reallocating the buf, if it needs room for the terminating null byte. --- diff --git a/src/wrbuf.c b/src/wrbuf.c index 972acff..7015bad 100644 --- a/src/wrbuf.c +++ b/src/wrbuf.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -262,8 +263,9 @@ 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 >= b->size) + wrbuf_grow(b, 1); + b->buf[b->pos] = '\0'; return b->buf; }