summaryrefslogtreecommitdiffstats
path: root/usr.bin/patch/util.c
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2014-12-25 21:51:28 +0000
committerpfg <pfg@FreeBSD.org>2014-12-25 21:51:28 +0000
commitf9a4136de0ddd1d48a33e089a7ee67f09fedebb4 (patch)
treee9f394a602a19bbe3aefd3701b9f5e9631df6b19 /usr.bin/patch/util.c
parenta5140616afea75587f25d7fc244b3a894d028b26 (diff)
downloadFreeBSD-src-f9a4136de0ddd1d48a33e089a7ee67f09fedebb4.zip
FreeBSD-src-f9a4136de0ddd1d48a33e089a7ee67f09fedebb4.tar.gz
patch: Bring in xstrdup and use it when appropriate.
The function savestr allows NULL return values during Plan A patching so in case of out of memory conditions, Plan B can step in. In many cases, NULL value is not properly handled, so use xstrdup here (it's outside Plan A/B patching, which means that even Plan B relies on successful operations). Clean up some whitespaces while here Obtained from: OpenBSD MFC after: 2 weeks
Diffstat (limited to 'usr.bin/patch/util.c')
-rw-r--r--usr.bin/patch/util.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/usr.bin/patch/util.c b/usr.bin/patch/util.c
index 6980676..6d696b0 100644
--- a/usr.bin/patch/util.c
+++ b/usr.bin/patch/util.c
@@ -202,6 +202,22 @@ savestr(const char *s)
}
/*
+ * Allocate a unique area for a string. Call fatal if out of memory.
+ */
+char *
+xstrdup(const char *s)
+{
+ char *rv;
+
+ if (!s)
+ s = "Oops";
+ rv = strdup(s);
+ if (rv == NULL)
+ fatal("out of memory\n");
+ return rv;
+}
+
+/*
* Vanilla terminal output (buffered).
*/
void
OpenPOWER on IntegriCloud