]> git.armaanb.net Git - dwm.git/blobdiff - dwm.c
dwm: use ecalloc, prevent theoretical overflow
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index f9e0c3d386073a5811ba606e962a2220b0768c57..6295831b976059a604bedb3db5025c6551be12af 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -557,7 +557,7 @@ configurenotify(XEvent *e) {
        XConfigureEvent *ev = &e->xconfigure;
        Bool dirty;
 
-       // TODO: updategeom handling sucks, needs to be simplified
+       /* TODO: updategeom handling sucks, needs to be simplified */
        if(ev->window == root) {
                dirty = (sw != ev->width || sh != ev->height);
                sw = ev->width;
@@ -630,8 +630,7 @@ Monitor *
 createmon(void) {
        Monitor *m;
 
-       if(!(m = (Monitor *)calloc(1, sizeof(Monitor))))
-               die("fatal: could not malloc() %u bytes\n", sizeof(Monitor));
+       m = ecalloc(1, sizeof(Monitor));
        m->tagset[0] = m->tagset[1] = 1;
        m->mfact = mfact;
        m->nmaster = nmaster;
@@ -1007,8 +1006,7 @@ manage(Window w, XWindowAttributes *wa) {
        Window trans = None;
        XWindowChanges wc;
 
-       if(!(c = calloc(1, sizeof(Client))))
-               die("fatal: could not malloc() %u bytes\n", sizeof(Client));
+       c = ecalloc(1, sizeof(Client));
        c->win = w;
        updatetitle(c);
        if(XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
@@ -1509,7 +1507,7 @@ setup(void) {
        drw = drw_create(dpy, screen, root, sw, sh);
        drw_load_fonts(drw, fonts, LENGTH(fonts));
        if (!drw->fontcount)
-               die("No fonts could be loaded.\n");
+               die("no fonts could be loaded.\n");
        bh = drw->fonts[0]->h + 2;
        updategeom();
        /* init atoms */
@@ -1572,7 +1570,7 @@ showhide(Client *c) {
 void
 sigchld(int unused) {
        if(signal(SIGCHLD, sigchld) == SIG_ERR)
-               die("Can't install SIGCHLD handler");
+               die("can't install SIGCHLD handler:");
        while(0 < waitpid(-1, NULL, WNOHANG));
 }
 
@@ -1788,8 +1786,7 @@ updategeom(void) {
 
                for(n = 0, m = mons; m; m = m->next, n++);
                /* only consider unique geometries as separate screens */
-               if(!(unique = (XineramaScreenInfo *)malloc(sizeof(XineramaScreenInfo) * nn)))
-                       die("fatal: could not malloc() %u bytes\n", sizeof(XineramaScreenInfo) * nn);
+               unique = ecalloc(nn, sizeof(XineramaScreenInfo));
                for(i = 0, j = 0; i < nn; i++)
                        if(isuniquegeom(unique, j, &info[i]))
                                memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo));
@@ -2054,7 +2051,7 @@ zoom(const Arg *arg) {
 int
 main(int argc, char *argv[]) {
        if(argc == 2 && !strcmp("-v", argv[1]))
-               die("dwm-"VERSION", © 2006-2014 dwm engineers, see LICENSE for details\n");
+               die("dwm-"VERSION", © 2006-2015 dwm engineers, see LICENSE for details\n");
        else if(argc != 1)
                die("usage: dwm [-v]\n");
        if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())