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