summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2022-12-21 22:38:54 +0100
committerAlejandro Colomar <alx@kernel.org>2022-12-21 22:38:54 +0100
commit66874ae1c514a3b1b33b08970bc832f5ee41beee (patch)
treebd532220fe8c97ad02ef988f36ce8774c336edf3
parent8a757718796fd3b2f165f335eb56a3820a227831 (diff)
strncat.3: EXAMPLES: Check the return of malloc(3)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--man3/strncat.33
1 files changed, 3 insertions, 0 deletions
diff --git a/man3/strncat.3 b/man3/strncat.3
index 3440e46e6..b34657034 100644
--- a/man3/strncat.3
+++ b/man3/strncat.3
@@ -87,6 +87,7 @@ Shlemiel the painter
.SH EXAMPLES
.\" SRC BEGIN (strncat.c)
.EX
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -110,6 +111,8 @@ main(void)
maxsize = nitems(pre) + strlen(src) \- strlen(post) +
nitems(new_post) + 1;
dest = malloc(sizeof(*dest) * maxsize);
+ if (dest == NULL)
+ err(EXIT_FAILURE, "malloc()");
dest[0] = \(aq\e0\(aq; // There's no 'cpy' function to this 'cat'.
strncat(dest, pre, nitems(pre));