* immutable: Fix crash when immmalloc() fails
@ 2021-04-30 23:14 Bruno Haible
0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2021-04-30 23:14 UTC (permalink / raw)
To: bug-gnulib
Compiling a testdir with CC="gcc -fanalyzer" produced this warning:
../../gllib/immutable.c:333:3: warning: use of NULL 'wp' where non-null expected [CWE-476] [-Wanalyzer-null-argument]
2021-04-30 Bruno Haible <bruno@clisp.org>
immutable: Fix crash when immmalloc() fails.
Found by GCC 11 '-fanalyzer'.
* lib/immutable.c (immstrdup): Don't crash when immmalloc() fails.
diff --git a/lib/immutable.c b/lib/immutable.c
index 35f7397..e4f3825 100644
--- a/lib/immutable.c
+++ b/lib/immutable.c
@@ -330,6 +330,8 @@ immstrdup (const char *string)
{
size_t size = strlen (string) + 1;
void *wp = immmalloc (size);
+ if (wp == NULL)
+ return NULL;
memcpy (wp, string, size);
return (const char *) immfreeze (wp);
}
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-30 23:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-30 23:14 immutable: Fix crash when immmalloc() fails Bruno Haible
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).