bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

immutable: Fix crash when immmalloc() fails


From: Bruno Haible
Subject: immutable: Fix crash when immmalloc() fails
Date: Sat, 01 May 2021 01:14:13 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-206-generic; KDE/5.18.0; x86_64; ; )

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 via email to

[Prev in Thread] Current Thread [Next in Thread]