git: 47204fd342e8 - stable/13 - sort: replace malloc+memset with calloc

From: Baptiste Daroussin <bapt_at_FreeBSD.org>
Date: Wed, 19 Oct 2022 08:01:23 UTC
The branch stable/13 has been updated by bapt:

URL: https://cgit.FreeBSD.org/src/commit/?id=47204fd342e8875c330d8c217e8261a2fb0f68f1

commit 47204fd342e8875c330d8c217e8261a2fb0f68f1
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2022-10-12 13:57:11 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2022-10-19 07:56:50 +0000

    sort: replace malloc+memset with calloc
    
    (cherry picked from commit ecc3c2916751a0aef5619ed8f0ba1cc37c0a22ba)
---
 usr.bin/sort/coll.c      |  6 ++----
 usr.bin/sort/file.c      |  3 +--
 usr.bin/sort/radixsort.c | 12 ++++--------
 3 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/usr.bin/sort/coll.c b/usr.bin/sort/coll.c
index ccd73e19d393..e3d388743d4a 100644
--- a/usr.bin/sort/coll.c
+++ b/usr.bin/sort/coll.c
@@ -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);
 }
diff --git a/usr.bin/sort/file.c b/usr.bin/sort/file.c
index b6b9d934e0ef..1fb02642b5c9 100644
--- a/usr.bin/sort/file.c
+++ b/usr.bin/sort/file.c
@@ -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)
diff --git a/usr.bin/sort/radixsort.c b/usr.bin/sort/radixsort.c
index 4c448fad69e9..578493f4d47c 100644
--- a/usr.bin/sort/radixsort.c
+++ b/usr.bin/sort/radixsort.c
@@ -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;