aboutsummaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-03 21:35:13 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-03 21:35:13 +0100
commit7b22939c20afa4f4a08c13a25d71f2720f0b6a29 (patch)
treecca1ec10d242fcaca03104c0fc86656223d1bdb9 /strbuf.c
parentUpdate gitignore to contain parse and *.x. (diff)
downloadcalp-7b22939c20afa4f4a08c13a25d71f2720f0b6a29.tar.gz
calp-7b22939c20afa4f4a08c13a25d71f2720f0b6a29.tar.xz
Loads of memmory fixes, among other.
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/strbuf.c b/strbuf.c
index 353b6d84..0dbaa0c7 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -25,9 +25,9 @@ int CONSTRUCTOR_DECL(strbuf, size_t len) {
int strbuf_realloc(strbuf* str, size_t len) {
#ifdef SAFE_STR
- if (str->mem == NULL || str->alloc == 0) {
+ if (str->mem == NULL /*|| str->alloc == -1*/) {
ERR("String memory not initialized");
- return 1;
+ // return 1;
}
#endif
str->mem = realloc(str->mem, len);
@@ -38,14 +38,12 @@ int strbuf_realloc(strbuf* str, size_t len) {
// int strbuf_free(strbuf* str) {
int FREE_DECL(strbuf) {
#ifdef SAFE_STR
- if (this->alloc == 0 || this->mem == NULL) {
- ERR("String not allocated");
- return 1;
- }
+ if (this->mem == NULL) return 1;
#endif
- // fprintf(stderr, "Memmory = %p | %4lu | %s\n", this->mem, this->alloc, this->mem);
free (this->mem);
+ this->mem = NULL;
this->alloc = 0;
+ this->len = 0;
return 0;
}
@@ -103,6 +101,12 @@ int strbuf_reset(strbuf* s)
return 0;
}
+int strbuf_realloc_copy(strbuf* dest, strbuf* src) {
+ strbuf_realloc(dest, src->len);
+ strbuf_copy(dest, src);
+ return 0;
+}
+
int strbuf_init_copy(strbuf* dest, strbuf* src) {
#ifdef SAFE_STR
if (dest->alloc != 0) {