From 97fafedd350b74076d8a8e31e23102fa22d4b430 Mon Sep 17 00:00:00 2001 From: Heikki Levanto Date: Tue, 8 Apr 2014 13:44:58 +0200 Subject: [PATCH] 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. --- src/wrbuf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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; } -- 1.7.10.4