From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Subject: immutable: Fix crash when immmalloc() fails
Date: Sat, 01 May 2021 01:14:13 +0200 [thread overview]
Message-ID: <2703361.22hd3GMMjE@omega> (raw)
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);
}
reply other threads:[~2021-04-30 23:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2703361.22hd3GMMjE@omega \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).