[hackers] [sent] replace malloc() with ecalloc() || Markus Teich

From: <git_AT_suckless.org>
Date: Fri, 4 Nov 2016 19:49:15 +0100 (CET)

commit 0ff43aaf341e89086fea10605021fb4a94c835ad
Author: Markus Teich <markus.teich_AT_stusta.mhn.de>
AuthorDate: Fri Nov 4 19:50:09 2016 +0100
Commit: Markus Teich <markus.teich_AT_stusta.mhn.de>
CommitDate: Fri Nov 4 19:50:09 2016 +0100

    replace malloc() with ecalloc()

diff --git a/sent.c b/sent.c
index 5fce290..6a4d565 100644
--- a/sent.c
+++ b/sent.c
_AT_@ -217,14 +217,11 @@ ffload(Slide *s)
         if (s->img->buf)
                 free(s->img->buf);
         /* internally the image is stored in 888 format */
- if (!(s->img->buf = malloc(3 * s->img->bufwidth * s->img->bufheight)))
- die("sent: Unable to allocate buffer for image:");
+ s->img->buf = ecalloc(s->img->bufwidth * s->img->bufheight, strlen("888"));
 
         /* scratch buffer to read row by row */
         rowlen = s->img->bufwidth * 2 * strlen("RGBA");
- row = malloc(rowlen);
- if (!row)
- die("sent: Unable to allocate buffer for image row:");
+ row = ecalloc(1, rowlen);
 
         /* extract window background color channels for transparency */
         bg_r = (sc[ColBg].pixel >> 16) % 256;
_AT_@ -275,9 +272,7 @@ ffprepare(Image *img)
                                        NULL, width, height, 32, 0)))
                 die("sent: Unable to create XImage");
 
- if (!(img->ximg->data = malloc(img->ximg->bytes_per_line * height)))
- die("sent: Unable to allocate data section for XImage");
-
+ img->ximg->data = ecalloc(height, img->ximg->bytes_per_line);
         if (!XInitImage(img->ximg))
                 die("sent: Unable to initiate XImage");
 
_AT_@ -583,8 +578,7 @@ xloadfonts()
         char *fstrs[LEN(fontfallbacks)];
 
         for (j = 0; j < LEN(fontfallbacks); j++) {
- if (!(fstrs[j] = malloc(MAXFONTSTRLEN)))
- die("sent: Unable to allocate fontstring:");
+ fstrs[j] = ecalloc(1, MAXFONTSTRLEN);
         }
 
         for (i = 0; i < NUMFONTSCALES; i++) {
Received on Fri Nov 04 2016 - 19:49:15 CET

This archive was generated by hypermail 2.3.0 : Fri Nov 04 2016 - 20:00:29 CET