diff --git a/package/gluon-web/src/template_lmo.c b/package/gluon-web/src/template_lmo.c index 8e5e17c2..94ebd123 100644 --- a/package/gluon-web/src/template_lmo.c +++ b/package/gluon-web/src/template_lmo.c @@ -80,9 +80,7 @@ static lmo_archive_t * lmo_open(const char *file) if ((in = open(file, O_RDONLY)) == -1) goto err; - if ((ar = (lmo_archive_t *)malloc(sizeof(*ar))) != NULL) - { - memset(ar, 0, sizeof(*ar)); + if ((ar = calloc(1, sizeof(*ar))) != NULL) { ar->fd = in; ar->size = s.st_size; @@ -140,11 +138,9 @@ int lmo_load_catalog(const char *lang, const char *dir) if (!dir || !(dh = opendir(dir))) goto err; - if (!(cat = malloc(sizeof(*cat)))) + if (!(cat = calloc(1, sizeof(*cat)))) goto err; - memset(cat, 0, sizeof(*cat)); - snprintf(cat->lang, sizeof(cat->lang), "%s", lang); snprintf(pattern, sizeof(pattern), "*.%s.lmo", lang); diff --git a/package/gluon-web/src/template_parser.c b/package/gluon-web/src/template_parser.c index 7bf42995..4f3ad15f 100644 --- a/package/gluon-web/src/template_parser.c +++ b/package/gluon-web/src/template_parser.c @@ -39,10 +39,9 @@ struct template_parser * template_open(const char *file) struct stat s; struct template_parser *parser; - if (!(parser = malloc(sizeof(*parser)))) + if (!(parser = calloc(1, sizeof(*parser)))) goto err; - memset(parser, 0, sizeof(*parser)); parser->fd = -1; parser->file = file; @@ -80,10 +79,9 @@ struct template_parser * template_string(const char *str, uint32_t len) return NULL; } - if (!(parser = malloc(sizeof(*parser)))) + if (!(parser = calloc(1, sizeof(*parser)))) goto err; - memset(parser, 0, sizeof(*parser)); parser->fd = -1; parser->size = len; diff --git a/package/gluon-web/src/template_utils.c b/package/gluon-web/src/template_utils.c index 505d09d2..c87da7c9 100644 --- a/package/gluon-web/src/template_utils.c +++ b/package/gluon-web/src/template_utils.c @@ -27,7 +27,7 @@ struct template_buffer * buf_init(int size) if (size <= 0) size = 1024; - buf = (struct template_buffer *)malloc(sizeof(struct template_buffer)); + buf = malloc(sizeof(*buf)); if (buf != NULL) {