summaryrefslogtreecommitdiffstats
path: root/usr.bin/patch/util.c
diff options
context:
space:
mode:
authortobias <tobias@openbsd.org>2014-12-13 10:31:07 +0000
committertobias <tobias@openbsd.org>2014-12-13 10:31:07 +0000
commit71847ebdc6411ce9154e1448ea3120fd6a57b2a0 (patch)
tree684ef80b5eab3290107c724e2983e5f59d1cd4d2 /usr.bin/patch/util.c
parentmacro cleanup; from Kaspars Bankovskis, tweaked a bit (diff)
downloadwireguard-openbsd-71847ebdc6411ce9154e1448ea3120fd6a57b2a0.tar.xz
wireguard-openbsd-71847ebdc6411ce9154e1448ea3120fd6a57b2a0.zip
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).
Diffstat (limited to 'usr.bin/patch/util.c')
-rw-r--r--usr.bin/patch/util.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/usr.bin/patch/util.c b/usr.bin/patch/util.c
index 876eda36e42..4db53a42b5b 100644
--- a/usr.bin/patch/util.c
+++ b/usr.bin/patch/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.37 2014/11/22 15:49:28 tobias Exp $ */
+/* $OpenBSD: util.c,v 1.38 2014/12/13 10:31:07 tobias Exp $ */
/*
* patch - a program to apply diffs to original files
@@ -192,6 +192,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