summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2022-12-21 22:35:37 +0100
committerAlejandro Colomar <alx@kernel.org>2022-12-21 22:35:37 +0100
commit8a757718796fd3b2f165f335eb56a3820a227831 (patch)
treee07c113464e4d58ed4e0b87bf16059d0076b9e24
parent3d395282860f7b86f65c6735351f24b52c486718 (diff)
strcpy.3: EXAMPLES: Check the return of malloc(3)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--man3/strcpy.35
1 files changed, 5 insertions, 0 deletions
diff --git a/man3/strcpy.3 b/man3/strcpy.3
index 79c0d1c7b..c5818b91f 100644
--- a/man3/strcpy.3
+++ b/man3/strcpy.3
@@ -147,6 +147,7 @@ Shlemiel the painter
.SH EXAMPLES
.\" SRC BEGIN (strcpy.c)
.EX
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -161,7 +162,11 @@ main(void)
maxsize = strlen("Hello ") + strlen("world") + strlen("!") + 1;
buf1 = malloc(sizeof(*buf1) * maxsize);
+ if (buf1 == NULL)
+ err(EXIT_FAILURE, "malloc()");
buf2 = malloc(sizeof(*buf2) * maxsize);
+ if (buf2 == NULL)
+ err(EXIT_FAILURE, "malloc()");
p = buf1;
p = stpcpy(p, "Hello ");