From fa682decde0b4513f5ce6084df590107359158f5 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 4 Nov 2023 10:10:34 -0700 Subject: doDirectory: add missing check for malloc() returning NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves gcc analyzer warning: mkfontscale.c: In function ‘doDirectory’: mkfontscale.c:974:17: warning: use of possibly-NULL ‘s’ where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument] 974 | memcpy(s, xlfd_name, l - 11); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Alan Coopersmith --- mkfontscale.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mkfontscale.c b/mkfontscale.c index d692e3c..2b07c67 100644 --- a/mkfontscale.c +++ b/mkfontscale.c @@ -971,6 +971,10 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo) char *s; s = malloc(l - 10); + if (s == NULL) { + fprintf(stderr, "Couldn't allocate xlfd name\n"); + exit(1); + } memcpy(s, xlfd_name, l - 11); s[l - 11] = '\0'; xlfd = listCons(s, xlfd); -- cgit v1.2.3