Add xcalloc wrapper

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Mon, 17 Sep 2012 19:03:35 +0200

malloc and realloc are called through xmalloc and xrealloc, so calloc should
be called through xcalloc.
---
 st.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/st.c b/st.c
index d5ecf61..df7f8d8 100644
--- a/st.c
+++ b/st.c
_AT_@ -324,6 +324,7 @@ static int isfullutf8(char *, int);
 
 static void *xmalloc(size_t);
 static void *xrealloc(void *, size_t);
+static void *xcalloc(size_t nmemb, size_t size);
 
 static void (*handler[LASTEvent])(XEvent *) = {
 	[KeyPress] = kpress,
_AT_@ -373,6 +374,14 @@ xrealloc(void *p, size_t len) {
 	return p;
 }
 
+void *
+xcalloc(size_t nmemb, size_t size) {
+	void *p = calloc(nmemb, size);
+	if(!p)
+		die("Out of memory\n");
+	return p;
+}
+
 int
 utf8decode(char *s, long *u) {
 	uchar c;
_AT_@ -1801,8 +1810,8 @@ tresize(int col, int row) {
 	/* allocate any new rows */
 	for(/* i == minrow */; i < row; i++) {
 		term.dirty[i] = 1;
-		term.line[i] = calloc(col, sizeof(Glyph));
-		term.alt [i] = calloc(col, sizeof(Glyph));
+		term.line[i] = xcalloc(col, sizeof(Glyph));
+		term.alt [i] = xcalloc(col, sizeof(Glyph));
 	}
 	if(col > term.col) {
 		bool *bp = term.tabs + term.col;
-- 
1.7.10.4
--ZGiS0Q5IWpPtfppv
Content-Type: text/x-diff; charset=utf-8
Content-Disposition: attachment; filename="0002-Add-newline-in-error-messages.patch"
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Mon Sep 17 2012 - 20:36:04 CEST