From 66874ae1c514a3b1b33b08970bc832f5ee41beee Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 21 Dec 2022 22:38:54 +0100 Subject: strncat.3: EXAMPLES: Check the return of malloc(3) Signed-off-by: Alejandro Colomar --- man3/strncat.3 | 3 +++ 1 file changed, 3 insertions(+) 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 #include #include #include @@ -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)); -- cgit v1.2.3