From: Siraaj Khandkar Date: Thu, 5 Mar 2020 17:06:59 +0000 (-0500) Subject: Switch from malloc to calloc X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=3c836bfdd8538a46a4cb3e9493bf3dbab2b4b2b5;p=khatus.git Switch from malloc to calloc --- diff --git a/x5/khatus.c b/x5/khatus.c index c7660b4..34ac42f 100644 --- a/x5/khatus.c +++ b/x5/khatus.c @@ -111,7 +111,7 @@ void parse_opts_opt_s(Config *cfg, int argc, char *argv[], int i) { if (i < argc) { - cfg->separator = malloc((strlen(argv[i]) + 1) * sizeof(char)); + cfg->separator = calloc((strlen(argv[i]) + 1), sizeof(char)); strcpy(cfg->separator, argv[i]); opts_parse_any(cfg, argc, argv, ++i); } else { @@ -123,7 +123,7 @@ void parse_opts_opt_t(Config *cfg, int argc, char *argv[], int i) { if (i < argc) { - cfg->timefmt = malloc((strlen(argv[i]) + 1) * sizeof(char)); + cfg->timefmt = calloc((strlen(argv[i]) + 1), sizeof(char)); strcpy(cfg->timefmt, argv[i]); opts_parse_any(cfg, argc, argv, ++i); } else { @@ -156,7 +156,7 @@ parse_opts_spec(Config *cfg, int argc, char *argv[], int i) usage("[spec] Invalid width: \"%s\", for file \"%s\"\n", w, n); if (!is_pos_num(t)) usage("[spec] Invalid TTL: \"%s\", for file \"%s\"\n", t, n); - File *f = malloc(sizeof(struct File)); + File *f = calloc(1, sizeof(struct File)); if (f) { f->name = n; f->fd = -1; @@ -270,7 +270,7 @@ main(int argc, char *argv[]) nfiles++; } width += (seplen * (nfiles - 1)); - buf = malloc(width + 1); + buf = calloc(1, width + 1); if (buf == NULL) fatal("[memory] Failed to allocate buffer of %d bytes", width); memset(buf, ' ', width);