]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
immutable: Fix crash when immmalloc() fails.
authorBruno Haible <bruno@clisp.org>
Fri, 30 Apr 2021 23:13:47 +0000 (01:13 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 30 Apr 2021 23:13:47 +0000 (01:13 +0200)
Found by GCC 11 '-fanalyzer'.

* lib/immutable.c (immstrdup): Don't crash when immmalloc() fails.

ChangeLog
lib/immutable.c

index cb2c68df6817bd1b712f44dc5212d0c4832d7c1e..3173be96df2f7ad3e672c163e6c795f22bb1869f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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.
+
 2021-04-30  Bruno Haible  <bruno@clisp.org>
 
        supersede: Fix crash when malloc() fails.
index 35f73978f22e98846b7cbd60f46055dd375cae2d..e4f3825352176b6444fea69c5e9e67ff578db029 100644 (file)
@@ -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);
 }