diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-05 17:53:13 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-05 18:16:19 +0100 |
commit | a19be8473c3060c10c76c85d633dc546eabd447a (patch) | |
tree | fea97d5207a7c0b5783efc979ebbf9317ccbaba7 /strbuf.c | |
parent | Fix append. (diff) | |
download | calp-a19be8473c3060c10c76c85d633dc546eabd447a.tar.gz calp-a19be8473c3060c10c76c85d633dc546eabd447a.tar.xz |
Fix most memmory problems.
Diffstat (limited to 'strbuf.c')
-rw-r--r-- | strbuf.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -50,6 +50,12 @@ FREE_F(strbuf) { * TODO this should do bounds check */ int strbuf_append(strbuf* s, char c) { +#ifdef SAFE_STR + if (s->len > s->alloc) { + ERR("Not enough memmory allocated"); + return 1; + } +#endif s->mem[s->len] = c; s->ptr = ++s->len; return 0; @@ -62,13 +68,15 @@ int strbuf_cap(strbuf* s) { int strbuf_copy(strbuf* dest, strbuf* src) { #ifdef SAFE_STR - if (dest->alloc < src->len) { + if (dest->alloc + 1 < src->len) { ERR("Not enough memmory allocated"); return 1; } #endif dest->len = src->len; memcpy(dest->mem, src->mem, src->len); + // TODO should this be here? + strbuf_cap(dest); return 0; } |