Simpler to use _eina_strbuf_resize
authorenglebass <englebass>
Sat, 6 Feb 2010 20:42:03 +0000 (20:42 +0000)
committerenglebass <englebass@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 6 Feb 2010 20:42:03 +0000 (20:42 +0000)
Add space for '\0' in _eina_strbuf_resize, so that we alwyas just pass
inn the wanted string space as requirement.

Correct len in eina_strbuf_append_n, we needed +1 for '\0' for resize
and strlcpy, but not for ->len

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@45945 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/eina_strbuf.c

index 8ea2771..4122588 100644 (file)
@@ -97,7 +97,7 @@ eina_strbuf_append(Eina_Strbuf *buf, const char *str)
    EINA_MAGIC_CHECK_STRBUF(buf);
 
    len = strlen(str);
-   _eina_strbuf_resize(buf, buf->len + len + 1);
+   _eina_strbuf_resize(buf, buf->len + len);
    eina_strlcpy(buf->buf + buf->len, str, buf->size - buf->len);
    buf->len += len;
 }
@@ -117,10 +117,9 @@ eina_strbuf_append_n(Eina_Strbuf *buf, const char *str, unsigned int maxlen)
 
    len = strlen(str);
    if (len > maxlen) len = maxlen;
-   len += 1; // for '\0'
    _eina_strbuf_resize(buf, buf->len + len);
 
-   eina_strlcpy(buf->buf + buf->len, str, len);
+   eina_strlcpy(buf->buf + buf->len, str, len + 1); // + 1 for '\0'
    buf->len += len;
 }
 
@@ -195,6 +194,7 @@ eina_strbuf_remove(Eina_Strbuf *buf, unsigned int start, unsigned int end)
    tail_len = buf->len - end + 1; /* includes '\0' */
    memmove(buf->buf + start, buf->buf + end, tail_len);
    buf->len -= remove_len;
+   _eina_strbuf_resize(buf, buf->len);
 }
 
 /**
@@ -406,6 +406,8 @@ _eina_strbuf_resize(Eina_Strbuf *buf, size_t size)
    size_t new_size;
    size_t new_step;
 
+   size += 1; // Add extra space for '\0'
+
    new_size = buf->size;
    new_step = buf->step;