includes: add xalloc.h to unify memory allocations

The xalloc.h provides necessary error checking.

Signed-off-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola
2011-10-09 21:29:26 +02:00
parent 4bd36d1483
commit 1ef14f4bf9
7 changed files with 94 additions and 48 deletions

View File

@ -13,6 +13,7 @@
#include "proc/sysinfo.h"
#include "c.h"
#include "nls.h"
#include "xalloc.h"
#include <errno.h>
#include <fcntl.h>
@ -54,12 +55,9 @@ static void setsize(int i)
}
scr_size = nrows * ncols;
if (screen == NULL)
screen = (char *)malloc(scr_size);
screen = (char *)xmalloc(scr_size);
else
screen = (char *)realloc(screen, scr_size);
if (screen == NULL)
err(EXIT_FAILURE, _("cannot allocate %zu bytes"), scr_size);
screen = (char *)xrealloc(screen, scr_size);
memset(screen, ' ', scr_size - 1);
*(screen + scr_size - 2) = '\0';