summary refs log tree commit diff
diff options
context:
space:
mode:
authorokan <okan>2020-01-22 19:58:35 +0000
committerokan <okan>2020-01-22 19:58:35 +0000
commit83de84b7f822a2211d81d9bb11d4a3e41588c364 (patch)
treef714a660d5dc322406ddbb0655f6208c56f3cf8e
parent2fc191f978225291055477f42d2b59afd62b5c75 (diff)
downloadcwm-83de84b7f822a2211d81d9bb11d4a3e41588c364.tar.gz
cwm-83de84b7f822a2211d81d9bb11d4a3e41588c364.tar.xz
cwm-83de84b7f822a2211d81d9bb11d4a3e41588c364.zip
add, then use, xvasprintf, checking for appropriate return.
-rw-r--r--calmwm.h2
-rw-r--r--screen.c5
-rw-r--r--xmalloc.c15
3 files changed, 15 insertions, 7 deletions
diff --git a/calmwm.h b/calmwm.h
index 00f42be..ac4cd3b 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -598,5 +598,7 @@ char			*xstrdup(const char *);
 int			 xasprintf(char **, const char *, ...)
 			    __attribute__((__format__ (printf, 2, 3)))
 			    __attribute__((__nonnull__ (2)));
+int			 xvasprintf(char **, const char *, va_list)
+			    __attribute__((__nonnull__ (2)));
 
 #endif /* _CALMWM_H_ */
diff --git a/screen.c b/screen.c
index d81a134..1ddf679 100644
--- a/screen.c
+++ b/screen.c
@@ -275,15 +275,12 @@ void
 screen_prop_win_draw(struct screen_ctx *sc, const char *fmt, ...)
 {
 	va_list			 ap;
-	int			 i;
 	char			*text;
 	XGlyphInfo		 extents;
 
 	va_start(ap, fmt);
-	i = vasprintf(&text, fmt, ap);
+	xvasprintf(&text, fmt, ap);
 	va_end(ap);
-	if (i < 0 || text == NULL)
-		err(1, "vasprintf");
 
 	XftTextExtentsUtf8(X_Dpy, sc->xftfont, (const FcChar8*)text,
 	    strlen(text), &extents);
diff --git a/xmalloc.c b/xmalloc.c
index 9cf824a..69973de 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -91,11 +91,20 @@ xasprintf(char **ret, const char *fmt, ...)
 	int	 i;
 
 	va_start(ap, fmt);
-	i = vasprintf(ret, fmt, ap);
+	i = xvasprintf(ret, fmt, ap);
 	va_end(ap);
 
-	if (i < 0 || *ret == NULL)
-		err(1, "asprintf");
+	return(i);
+}
+
+int
+xvasprintf(char **ret, const char *fmt, va_list ap)
+{
+	int	 i;
+
+	i = vasprintf(ret, fmt, ap);
+	if (i == -1)
+		err(1, "vasprintf");
 
 	return(i);
 }