a57977
From d2f33b7005540aef5ce79479d598cdcc10d397f9 Mon Sep 17 00:00:00 2001
a57977
From: "Barton E. Schaefer" <schaefer@zsh.org>
a57977
Date: Thu, 24 Jul 2014 08:45:16 -0700
a57977
Subject: [PATCH] 32853: redefine VARARR() to use heap rather than stack
a57977
 allocation
a57977
a57977
Upstream-commit: 2f0efe9f592255d0d83c0929423cc397bb1ebfa4
a57977
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
a57977
---
a57977
 Src/mem.c        | 5 ++++-
a57977
 Src/zsh_system.h | 5 +++++
a57977
 2 files changed, 9 insertions(+), 1 deletion(-)
a57977
a57977
diff --git a/Src/mem.c b/Src/mem.c
a57977
index 5275c6c..c4745a5 100644
a57977
--- a/Src/mem.c
a57977
+++ b/Src/mem.c
a57977
@@ -856,7 +856,10 @@ zrealloc(void *ptr, size_t size)
a57977
 	ptr = NULL;
a57977
     } else {
a57977
 	/* If ptr is NULL, then behave like malloc */
a57977
-	ptr = malloc(size);
a57977
+	if (!(ptr = (void *) malloc(size))) {
a57977
+	    zerr("fatal error: out of memory");
a57977
+	    exit(1);
a57977
+	}
a57977
     }
a57977
     unqueue_signals();
a57977
 
a57977
diff --git a/Src/zsh_system.h b/Src/zsh_system.h
a57977
index f385330..427c25f 100644
a57977
--- a/Src/zsh_system.h
a57977
+++ b/Src/zsh_system.h
a57977
@@ -286,11 +286,16 @@ struct timezone {
a57977
 # include <limits.h>
a57977
 #endif
a57977
 
a57977
+#ifdef USE_STACK_ALLOCATION
a57977
+#warning compiling with USE_STACK_ALLOCATION
a57977
 #ifdef HAVE_VARIABLE_LENGTH_ARRAYS
a57977
 # define VARARR(X,Y,Z)	X (Y)[Z]
a57977
 #else
a57977
 # define VARARR(X,Y,Z)	X *(Y) = (X *) alloca(sizeof(X) * (Z))
a57977
 #endif
a57977
+#else
a57977
+# define VARARR(X,Y,Z)	X *(Y) = (X *) zhalloc(sizeof(X) * (Z))
a57977
+#endif
a57977
 
a57977
 /* we should handle unlimited sizes from pathconf(_PC_PATH_MAX) */
a57977
 /* but this is too much trouble                                 */
a57977
-- 
a57977
2.1.0
a57977