[hackers] [PATCH 7/8] drw: misc fixes

From: Markus Teich <markus.teich_AT_stusta.mhn.de>
Date: Sun, 22 May 2016 22:29:24 +0200

---
 drw.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drw.c b/drw.c
index 0adf33e..80383c9 100644
--- a/drw.c
+++ b/drw.c
_AT_@ -63,9 +63,8 @@ utf8decode(const char *c, long *u, size_t clen)
 Drw *
 drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
 {
-	Drw *drw;
+	Drw *drw = ecalloc(1, sizeof(Drw));
 
-	drw = ecalloc(1, sizeof(Drw));
 	drw->dpy = dpy;
 	drw->screen = screen;
 	drw->root = root;
_AT_@ -81,6 +80,9 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
 void
 drw_resize(Drw *drw, unsigned int w, unsigned int h)
 {
+	if (!drw)
+		return;
+
 	drw->w = w;
 	drw->h = h;
 	if (drw->drawable)
_AT_@ -365,6 +367,9 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex
 void
 drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
 {
+	if (!drw)
+		return;
+
 	XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y);
 	XSync(drw->dpy, False);
 }
_AT_@ -397,7 +402,9 @@ drw_cur_create(Drw *drw, int shape)
 {
 	Cur *cur;
 
-	cur = ecalloc(1, sizeof(Cur));
+	if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
+		return NULL;
+
 	cur->cursor = XCreateFontCursor(drw->dpy, shape);
 
 	return cur;
_AT_@ -408,6 +415,7 @@ drw_cur_free(Drw *drw, Cur *cursor)
 {
 	if (!cursor)
 		return;
+
 	XFreeCursor(drw->dpy, cursor->cursor);
 	free(cursor);
 }
-- 
2.7.3
Received on Sun May 22 2016 - 22:29:24 CEST

This archive was generated by hypermail 2.3.0 : Sun May 22 2016 - 22:36:33 CEST