summary refs log tree commit diff
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
parent73be7ee553b1df74bfccb7742c79b620aec828ce (diff)
downloadzsh-b4c2ea2cece1adeaa915f6c12f310f2268a58751.tar.gz
zsh-b4c2ea2cece1adeaa915f6c12f310f2268a58751.tar.xz
zsh-b4c2ea2cece1adeaa915f6c12f310f2268a58751.zip
27125: handle nested use of colour code buffer allocation
-rw-r--r--ChangeLog7
-rw-r--r--Src/prompt.c16
2 files changed, 20 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index fea458cff..323ade3a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-07-10  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* 27125: Src/prompt.c: handle nested use of colour code buffer
+	allocation.
+
 2009-07-10  Peter Stephenson  <pws@csr.com>
 
 	* 27122: Doc/Zsh/options.yo, Src/jobs.c, Src/options.c, Src/zsh.h:
@@ -11945,5 +11950,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.4733 $
+* $Revision: 1.4734 $
 *****************************************************
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);