diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-03 21:35:13 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-03 21:35:13 +0100 |
commit | 7b22939c20afa4f4a08c13a25d71f2720f0b6a29 (patch) | |
tree | cca1ec10d242fcaca03104c0fc86656223d1bdb9 /strbuf.c | |
parent | Update gitignore to contain parse and *.x. (diff) | |
download | calp-7b22939c20afa4f4a08c13a25d71f2720f0b6a29.tar.gz calp-7b22939c20afa4f4a08c13a25d71f2720f0b6a29.tar.xz |
Loads of memmory fixes, among other.
Diffstat (limited to 'strbuf.c')
-rw-r--r-- | strbuf.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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) { |