[PATCH 1/7] pg: use xalloc for memory allocation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Davidlohr Bueso <dave@xxxxxxx>
Date: Fri, 22 Oct 2010 12:22:09 -0300
Subject: [PATCH 1/7] pg: use xalloc for memory allocation

Signed-off-by: Davidlohr Bueso <dave@xxxxxxx>
---
 text-utils/pg.c |   20 +++-----------------
 1 files changed, 3 insertions(+), 17 deletions(-)

diff --git a/text-utils/pg.c b/text-utils/pg.c
index 24c1221..6827523 100644
--- a/text-utils/pg.c
+++ b/text-utils/pg.c
@@ -60,6 +60,7 @@
 #include <term.h>
 
 #include "nls.h"
+#include "xalloc.h"
 #include "widechar.h"
 
 #define	READBUF		LINE_MAX	/* size of input buffer */
@@ -213,21 +214,6 @@ quit(int status)
 }
 
 /*
- * 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.
  */
 static void
@@ -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 == '^') {
-- 
1.7.0.4




--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux