From ef06e8e8a1a5254ff6d506b0d3e2a3ce4f9ba339 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Fri, 21 Apr 2000 15:27:40 +0000 Subject: [PATCH] Check return value of strdup(3) for NULL in example code (duh). --- src/lib/libc/string/strdup.3 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/libc/string/strdup.3 b/src/lib/libc/string/strdup.3 index 457b8322..2734bf45 100644 --- a/src/lib/libc/string/strdup.3 +++ b/src/lib/libc/string/strdup.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: strdup.3,v 1.8 2000/04/21 15:24:20 aaron Exp $ +.\" $OpenBSD: strdup.3,v 1.9 2000/04/21 15:27:40 aaron Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -63,7 +63,10 @@ to an allocated area of memory containing the null-terminated string .Bd -literal -offset indent char *p; -p = strdup("foobar"); +if ((p = strdup("foobar")) == NULL) { + fprintf(stderr, "Out of memory.\en"); + exit(1); +} .Ed .Sh SEE ALSO .Xr free 3 ,