From 9adc16fb6f24cc28fa84832675516215cb604a8e Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Mon, 1 Apr 2024 20:13:43 +0200 Subject: Overflow checking by using reallocarray() --- FICS/makerank.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/FICS/makerank.c b/FICS/makerank.c index 3e33ac9..a86b0ec 100644 --- a/FICS/makerank.c +++ b/FICS/makerank.c @@ -121,10 +121,10 @@ LoadEntries(void) int listsize; listsize = 100; - list = malloc(sizeof(ENTRY *) * listsize); + list = reallocarray(NULL, sizeof(ENTRY *), listsize); if (list == NULL) - err(1, "%s: malloc", __func__); + err(1, "%s: reallocarray", __func__); for (letter1 = 'a'; letter1 <= 'z'; letter1++) { printf("Loading %c's.\n", letter1); @@ -237,10 +237,11 @@ makerank(void) for (rtype = 0; rtype < 4; rtype++) { sortnum = 0; sortmesize = 100; - sortme = malloc(sizeof(ENTRY *) * sortmesize); + sortme = reallocarray(NULL, sizeof(ENTRY *), + sortmesize); if (sortme == NULL) - err(1, "%s: malloc", __func__); + err(1, "%s: reallocarray", __func__); for (i = 0; i < n; i++) { if (list[i]->r[rtype].rating) { -- cgit v1.2.3