From: Davidlohr Bueso Date: Fri, 22 Oct 2010 15:22:09 +0000 (-0300) Subject: pg: use xalloc for memory allocation X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3a342a429b0576efeaf875bfb102f5b55f7c9b4;p=util-linux pg: use xalloc for memory allocation Signed-off-by: Davidlohr Bueso --- diff --git a/text-utils/pg.c b/text-utils/pg.c index 24c12217..68275238 100644 --- a/text-utils/pg.c +++ b/text-utils/pg.c @@ -60,6 +60,7 @@ #include #include "nls.h" +#include "xalloc.h" #include "widechar.h" #define READBUF LINE_MAX /* size of input buffer */ @@ -212,21 +213,6 @@ quit(int status) exit(status < 0100 ? status : 077); } -/* - * Memory allocator including check. - */ -static char * -smalloc(size_t s) -{ - char *m = (char *)malloc(s); - if (m == NULL) { - const char *p = _("Out of memory\n"); - write(2, p, strlen(p)); - quit(++exitstatus); - } - return m; -} - /* * Usage message and similar routines. */ @@ -549,7 +535,7 @@ endline(unsigned col, char *s) static void cline(void) { - char *buf = (char *)smalloc(ttycols + 2); + char *buf = xmalloc(ttycols + 2); memset(buf, ' ', ttycols + 2); buf[0] = '\r'; buf[ttycols + 1] = '\r'; @@ -601,7 +587,7 @@ getcount(char *cmdstr) if (*cmdstr == '\0') return 1; - buf = (char *)smalloc(strlen(cmdstr) + 1); + buf = xmalloc(strlen(cmdstr) + 1); strcpy(buf, cmdstr); if (cmd.key != '\0') { if (cmd.key == '/' || cmd.key == '?' || cmd.key == '^') {