sort: replace malloc+memset with calloc

This commit is contained in:
Baptiste Daroussin 2022-10-12 15:57:11 +02:00
parent a312f3e742
commit ecc3c29167
3 changed files with 7 additions and 14 deletions

View file

@ -73,8 +73,7 @@ keys_array_alloc(void)
size_t sz;
sz = keys_array_size();
ka = sort_malloc(sz);
memset(ka, 0, sz);
ka = sort_calloc(1, sz);
return (ka);
}
@ -157,8 +156,7 @@ sort_list_item_alloc(void)
size_t sz;
sz = sizeof(struct sort_list_item) + keys_array_size();
si = sort_malloc(sz);
memset(si, 0, sz);
si = sort_calloc(1, sz);
return (si);
}

View file

@ -615,8 +615,7 @@ file_reader_init(const char *fsrc)
if (fsrc == NULL)
fsrc = "-";
ret = sort_malloc(sizeof(struct file_reader));
memset(ret, 0, sizeof(struct file_reader));
ret = sort_calloc(1, sizeof(struct file_reader));
ret->elsymb = '\n';
if (sort_opts_vals.zflag)

View file

@ -225,8 +225,7 @@ add_to_sublevel(struct sort_level *sl, struct sort_list_item *item, size_t indx)
ssl = sl->sublevels[indx];
if (ssl == NULL) {
ssl = sort_malloc(sizeof(struct sort_level));
memset(ssl, 0, sizeof(struct sort_level));
ssl = sort_calloc(1, sizeof(struct sort_level));
ssl->level = sl->level + 1;
sl->sublevels[indx] = ssl;
@ -416,8 +415,7 @@ run_sort_level_next(struct sort_level *sl)
}
sl->sln = 256;
sl->sublevels = sort_malloc(slsz);
memset(sl->sublevels, 0, slsz);
sl->sublevels = sort_calloc(1, slsz);
sl->real_sln = 0;
@ -569,8 +567,7 @@ run_top_sort_level(struct sort_level *sl)
sl->start_position = 0;
sl->sln = 256;
sl->sublevels = sort_malloc(slsz);
memset(sl->sublevels, 0, slsz);
sl->sublevels = sort_calloc(1, slsz);
for (size_t i = 0; i < sl->tosort_num; ++i)
place_item(sl, i);
@ -696,8 +693,7 @@ run_sort(struct sort_list_item **base, size_t nmemb)
}
#endif
sl = sort_malloc(sizeof(struct sort_level));
memset(sl, 0, sizeof(struct sort_level));
sl = sort_calloc(1, sizeof(struct sort_level));
sl->tosort = base;
sl->tosort_num = nmemb;