--- cfg_buf.c 2002/07/04 14:51:21 1.2
+++ cfg_buf.c 2002/07/05 17:15:14 1.3
@@ -48,7 +48,7 @@
return CFG_OK;
}
-cfg_rc_t cfg_buf_resize(cfg_buf_t *buf, int n)
+cfg_rc_t cfg_buf_resize(cfg_buf_t *buf, signed int n)
{
char *cp;
@@ -65,9 +65,9 @@
else {
/* shrink or grow buffer */
if (buf->buf_ptr == NULL) {
- if ((buf->buf_ptr = malloc(n)) == NULL)
+ if ((buf->buf_ptr = malloc(n+1)) == NULL)
return CFG_ERR_SYS;
- buf->buf_size = n;
+ buf->buf_size = n+1;
buf->buf_len = 0;
}
else {
@@ -75,9 +75,9 @@
return CFG_ERR_SYS;
buf->buf_ptr = cp;
buf->buf_size += n;
- if (buf->buf_len > buf->buf_size) {
- buf->buf_len = buf->buf_size;
- *(buf->buf_ptr + buf->buf_len - 1) = '\0';
+ if (buf->buf_len >= buf->buf_size) {
+ buf->buf_len = buf->buf_size-1;
+ *(buf->buf_ptr + buf->buf_len) = '\0';
}
}
}
@@ -104,7 +104,7 @@
return CFG_ERR_ARG;
if ((n = cfg_fmt_vsprintf(NULL, -1, fmt, ap)) == -1)
return CFG_ERR_FMT;
- if ((rc = cfg_buf_resize(buf, n+1)) != CFG_OK)
+ if ((rc = cfg_buf_resize(buf, n)) != CFG_OK)
return rc;
if ((n = cfg_fmt_vsprintf(buf->buf_ptr + buf->buf_len,
buf->buf_size - buf->buf_len,
|