[dev] [st][PATCH] Add xstrdup function

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Tue, 4 Feb 2014 18:06:54 +0100

Since we are using xmalloc, xrealloc ..., then it is not logical
call directly to strdup.

Signed-off-by: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
---
 st.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/st.c b/st.c
index 6e7077a..49dd889 100644
--- a/st.c
+++ b/st.c
_AT_@ -441,6 +441,7 @@ static int isfullutf8(char *, int);
 static ssize_t xwrite(int, char *, size_t);
 static void *xmalloc(size_t);
 static void *xrealloc(void *, size_t);
+static char *xstrdup(char *s);
 
 static void (*handler[LASTEvent])(XEvent *) = {
 	[KeyPress] = kpress,
_AT_@ -529,6 +530,16 @@ xrealloc(void *p, size_t len) {
 	return p;
 }
 
+char *
+xstrdup(char *s) {
+	char *p = strdup(s);
+
+	if (!p)
+		die("Out of memory\n");
+
+	return p;
+}
+
 int
 utf8decode(char *s, long *u) {
 	uchar c;
_AT_@ -3789,7 +3800,7 @@ main(int argc, char *argv[]) {
 		if(argc > 1) {
 			opt_cmd = &argv[1];
 			if(argv[1] != NULL && opt_title == NULL) {
-				titles = strdup(argv[1]);
+				titles = xstrdup(argv[1]);
 				opt_title = basename(titles);
 			}
 		}
-- 
1.8.5.3
Received on Tue Feb 04 2014 - 18:06:54 CET

This archive was generated by hypermail 2.3.0 : Tue Feb 04 2014 - 18:12:05 CET