From 86f7e40446106f8365df4f52af4ec2ee5dcb37aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 21 Jan 2019 11:42:12 +0100 Subject: Remove all explicit malloc's. --- parse.c | 2 +- strbuf.c | 20 ++++++++++---------- vcal.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/parse.c b/parse.c index 76eb2300..be7e0a6a 100644 --- a/parse.c +++ b/parse.c @@ -178,7 +178,7 @@ int handle_kv( return 3; } } else { - content_line* c = malloc(sizeof(*c)); + NEW(content_line, c); content_line_copy(c, cline); add_content_line (ev, c); } diff --git a/strbuf.c b/strbuf.c index 932b31e0..7f61313b 100644 --- a/strbuf.c +++ b/strbuf.c @@ -7,19 +7,19 @@ #define ERR(s) fprintf(stderr, "\x1B[0;31mERR\x1b[m (strbuf %3i): %s\n", __LINE__, s) #endif -int strbuf_init_0(strbuf* str) { - str->mem = NULL; - str->alloc = 0; - str->len = 0; - str->ptr = 0; +int CONSTRUCTOR_DECL(strbuf) { + this->mem = NULL; + this->alloc = 0; + this->len = 0; + this->ptr = 0; return 0; } -int strbuf_init_1(strbuf* str, size_t len) { - str->mem = malloc(len); - str->alloc = len; - str->ptr = 0; - str->len = 0; +int CONSTRUCTOR_DECL(strbuf, size_t len) { + this->mem = calloc(sizeof(*this->mem), len); + this->alloc = len; + this->ptr = 0; + this->len = 0; return 0; } diff --git a/vcal.c b/vcal.c index 1d1e521a..e1dd3d63 100644 --- a/vcal.c +++ b/vcal.c @@ -95,8 +95,8 @@ int push_event(vcalendar* cal, vevent* ev) { } int CONSTRUCTOR_DECL(vcalendar) { - this->events = malloc(sizeof(*this->events)); this->alloc = 1; + this->events = calloc(sizeof(*this->events), this->alloc); this->n_events = 0; return 0; } -- cgit v1.2.3