From c0b3ada3558c2b427ac3d02c64440a2b3a2683db Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Wed, 13 Dec 2023 23:21:10 +0100 Subject: Handle malloc() error correctly --- FICS/makerank.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'FICS') diff --git a/FICS/makerank.c b/FICS/makerank.c index 90a5c22..dd936fb 100644 --- a/FICS/makerank.c +++ b/FICS/makerank.c @@ -125,17 +125,15 @@ LoadEntries(void) if (GetPlayerInfo(pathInput, &e)) { if ((list[n] = malloc(sizeof(ENTRY))) == - NULL) { - fprintf(stderr, "malloc() failed!\n"); - } else { - memcpy(list[n], &e, sizeof(ENTRY)); - - if (++n == listsize) { - listsize += 100; - list = realloc(list, - listsize * - sizeof(ENTRY *)); - } + NULL) + err(1, "%s: malloc", __func__); + + memcpy(list[n], &e, sizeof(ENTRY)); + + if (++n == listsize) { + listsize += 100; + list = realloc(list, listsize * + sizeof(ENTRY *)); } } } -- cgit v1.2.3