[hackers] [dwm] dwm: use ecalloc, prevent theoretical overflow || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Tue, 20 Oct 2015 23:45:32 +0200 (CEST)

commit e3b7e1d620e18818222c1e5033356ae29dd49e7f
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
AuthorDate: Tue Oct 20 23:30:31 2015 +0200
Commit: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
CommitDate: Tue Oct 20 23:38:31 2015 +0200

    dwm: use ecalloc, prevent theoretical overflow

diff --git a/dwm.c b/dwm.c
index e2d7423..6295831 100644
--- a/dwm.c
+++ b/dwm.c
_AT_@ -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;
_AT_@ -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))) {
_AT_@ -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));
Received on Tue Oct 20 2015 - 23:45:32 CEST

This archive was generated by hypermail 2.3.0 : Tue Oct 20 2015 - 23:48:17 CEST