diff options
author | pfg <pfg@FreeBSD.org> | 2014-12-25 21:51:28 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2014-12-25 21:51:28 +0000 |
commit | f9a4136de0ddd1d48a33e089a7ee67f09fedebb4 (patch) | |
tree | e9f394a602a19bbe3aefd3701b9f5e9631df6b19 /usr.bin/patch/util.c | |
parent | a5140616afea75587f25d7fc244b3a894d028b26 (diff) | |
download | FreeBSD-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.c | 16 |
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 |