summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2015-10-20 23:30:31 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2015-10-20 23:38:31 +0200
commite3b7e1d620e18818222c1e5033356ae29dd49e7f (patch)
treee236df1cc254bca3e914befe359ac378d939a9eb
parentcleanup, dont use c++ style comments (diff)
downloaddwm-e3b7e1d620e18818222c1e5033356ae29dd49e7f.tar.gz
dwm-e3b7e1d620e18818222c1e5033356ae29dd49e7f.zip
dwm: use ecalloc, prevent theoretical overflow
-rw-r--r--dwm.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/dwm.c b/dwm.c
index e2d7423..6295831 100644
--- a/dwm.c
+++ b/dwm.c
@@ -630,8 +630,7 @@ Monitor *
630createmon(void) { 630createmon(void) {
631 Monitor *m; 631 Monitor *m;
632 632
633 if(!(m = (Monitor *)calloc(1, sizeof(Monitor)))) 633 m = ecalloc(1, sizeof(Monitor));
634 die("fatal: could not malloc() %u bytes\n", sizeof(Monitor));
635 m->tagset[0] = m->tagset[1] = 1; 634 m->tagset[0] = m->tagset[1] = 1;
636 m->mfact = mfact; 635 m->mfact = mfact;
637 m->nmaster = nmaster; 636 m->nmaster = nmaster;
@@ -1007,8 +1006,7 @@ manage(Window w, XWindowAttributes *wa) {
1007 Window trans = None; 1006 Window trans = None;
1008 XWindowChanges wc; 1007 XWindowChanges wc;
1009 1008
1010 if(!(c = calloc(1, sizeof(Client)))) 1009 c = ecalloc(1, sizeof(Client));
1011 die("fatal: could not malloc() %u bytes\n", sizeof(Client));
1012 c->win = w; 1010 c->win = w;
1013 updatetitle(c); 1011 updatetitle(c);
1014 if(XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) { 1012 if(XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
@@ -1788,8 +1786,7 @@ updategeom(void) {
1788 1786
1789 for(n = 0, m = mons; m; m = m->next, n++); 1787 for(n = 0, m = mons; m; m = m->next, n++);
1790 /* only consider unique geometries as separate screens */ 1788 /* only consider unique geometries as separate screens */
1791 if(!(unique = (XineramaScreenInfo *)malloc(sizeof(XineramaScreenInfo) * nn))) 1789 unique = ecalloc(nn, sizeof(XineramaScreenInfo));
1792 die("fatal: could not malloc() %u bytes\n", sizeof(XineramaScreenInfo) * nn);
1793 for(i = 0, j = 0; i < nn; i++) 1790 for(i = 0, j = 0; i < nn; i++)
1794 if(isuniquegeom(unique, j, &info[i])) 1791 if(isuniquegeom(unique, j, &info[i]))
1795 memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo)); 1792 memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo));