aboutsummaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-06 12:08:58 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-06 12:08:58 +0100
commitaf3cc906185d7273cf82b1339b63843062898120 (patch)
tree01d9cff85d6c4dfee3185a2402745d721f3636e8 /strbuf.c
parentRemove GC. (diff)
downloadcalp-af3cc906185d7273cf82b1339b63843062898120.tar.gz
calp-af3cc906185d7273cf82b1339b63843062898120.tar.xz
Code cleanup and add documentation.
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/strbuf.c b/strbuf.c
index 2f83767f..bf40d7fe 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -24,9 +24,12 @@ INIT_F(strbuf, size_t len) {
int strbuf_realloc(strbuf* str, size_t len) {
#ifdef SAFE_STR
- if (str->mem == NULL /*|| str->alloc == -1*/) {
+ if (str->mem == NULL) {
+ /* NOTE
+ * this isn't an error, since
+ * realloc(NULL, 10) ≡ malloc(10)
+ */
ERR("String memory not initialized");
- // return 1;
}
#endif
str->mem = realloc(str->mem, len);
@@ -34,7 +37,6 @@ int strbuf_realloc(strbuf* str, size_t len) {
return 0;
}
-// int strbuf_free(strbuf* str) {
FREE_F(strbuf) {
#ifdef SAFE_STR
if (this->mem == NULL) return 1;
@@ -46,9 +48,6 @@ FREE_F(strbuf) {
return 0;
}
-/*
- * TODO this should do bounds check
- */
int strbuf_append(strbuf* s, char c) {
#ifdef SAFE_STR
if (s->len > s->alloc) {
@@ -75,6 +74,7 @@ int strbuf_copy(strbuf* dest, strbuf* src) {
#endif
dest->len = src->len;
memcpy(dest->mem, src->mem, src->len);
+
// TODO should this be here?
strbuf_cap(dest);
return 0;