Compiling a testdir with CC="gcc -fanalyzer" produced this warning:
gllib/supersede.c:63:3: warning: use of possibly-NULL 'temp_filename' where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument] 2021-04-30 Bruno Haible <[email protected]> supersede: Fix crash when malloc() fails. Found by GCC 11 '-fanalyzer'. * lib/supersede.c (create_temp_file): Don't crash when malloc() fails. diff --git a/lib/supersede.c b/lib/supersede.c index 7371e20..61b4f04 100644 --- a/lib/supersede.c +++ b/lib/supersede.c @@ -60,6 +60,8 @@ create_temp_file (char *canon_filename, int flags, mode_t mode, /* The temporary file needs to be in the same directory, otherwise the final rename may fail. */ char *temp_filename = (char *) malloc (canon_filename_length + 7 + 1); + if (temp_filename == NULL) + return -1; memcpy (temp_filename, canon_filename, canon_filename_length); memcpy (temp_filename + canon_filename_length, ".XXXXXX", 7 + 1);
