projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use WRBUF for addinfo member of cql_transform_t
[yaz-moved-to-github.git]
/
src
/
wrbuf.c
diff --git
a/src/wrbuf.c
b/src/wrbuf.c
index
344e574
..
3c63170
100644
(file)
--- a/
src/wrbuf.c
+++ b/
src/wrbuf.c
@@
-1,5
+1,5
@@
/* This file is part of the YAZ toolkit.
/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2013 Index Data
+ * Copyright (C) Index Data
* See the file LICENSE for details.
*/
* See the file LICENSE for details.
*/
@@
-16,6
+16,7
@@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+#include <assert.h>
#include <yaz/wrbuf.h>
#include <yaz/snprintf.h>
#include <yaz/wrbuf.h>
#include <yaz/snprintf.h>
@@
-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)
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;
}
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)
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;
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)
{
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;
}
return b->buf;
}