about summary refs log tree commit diff
path: root/Src/prompt.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2009-07-10 21:32:44 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2009-07-10 21:32:44 +0000
commitb4c2ea2cece1adeaa915f6c12f310f2268a58751 (patch)
tree84c1f152a7f04a31e5fed0b085dc884a3618f4cf /Src/prompt.c
parent73be7ee553b1df74bfccb7742c79b620aec828ce (diff)
downloadzsh-b4c2ea2cece1adeaa915f6c12f310f2268a58751.tar.gz
zsh-b4c2ea2cece1adeaa915f6c12f310f2268a58751.tar.xz
zsh-b4c2ea2cece1adeaa915f6c12f310f2268a58751.zip
27125: handle nested use of colour code buffer allocation
Diffstat (limited to 'Src/prompt.c')
-rw-r--r--Src/prompt.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/Src/prompt.c b/Src/prompt.c
index e56b70d0b..afb9777a0 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -1764,13 +1764,18 @@ struct colour_sequences {
 struct colour_sequences fg_bg_sequences[2];
 
 /*
- * We need a buffer for colour sequence compostion.  It may
+ * We need a buffer for colour sequence composition.  It may
  * vary depending on the sequences set.  However, it's inefficient
  * allocating it separately every time we send a colour sequence,
  * so do it once per refresh.
  */
 static char *colseq_buf;
 
+/*
+ * Count how often this has been allocated, for recursive usage.
+ */
+static int colseq_buf_allocs;
+
 /**/
 void
 set_default_colour_sequences(void)
@@ -1801,9 +1806,13 @@ set_colour_code(char *str, char **var)
 mod_export void
 allocate_colour_buffer(void)
 {
-    char **atrs = getaparam("zle_highlight");
+    char **atrs;
     int lenfg, lenbg, len;
 
+    if (colseq_buf_allocs++)
+	return;
+
+    atrs = getaparam("zle_highlight");
     if (atrs) {
 	for (; *atrs; atrs++) {
 	    if (strpfx("fg_start_code:", *atrs)) {
@@ -1846,6 +1855,9 @@ allocate_colour_buffer(void)
 mod_export void
 free_colour_buffer(void)
 {
+    if (--colseq_buf_allocs)
+	return;
+
     DPUTS(!colseq_buf, "Freeing colour sequence buffer without alloc");
     /* Free buffer for colour code composition */
     free(colseq_buf);