summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-06-23 17:31:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-06-23 18:32:51 (GMT)
commit0111681ecfe4d04a354536e62af1cde7c49e1c40 (patch)
tree8ae428d62ebd897073b21013b8e5674afe067999
parent765428699a5381f113d19974720bc91b5bfeaf1d (diff)
downloadgit-0111681ecfe4d04a354536e62af1cde7c49e1c40.zip
git-0111681ecfe4d04a354536e62af1cde7c49e1c40.tar.gz
git-0111681ecfe4d04a354536e62af1cde7c49e1c40.tar.bz2
color: fix max-size comment
We use fixed-size buffers for colors, because we know our parsing cannot grow beyond a particular bound. However, our comment description has two issues: 1. It has the description in two forms: a short one, and one with more explanation. Over time the latter has been updated, but the former has not. Let's just drop the short one (after making sure everything it says is in the long one). 2. As of ff40d18 (parse_color: recognize "no$foo" to clear the $foo attribute, 2014-11-20), the per-attribute size bumped to "3" (because "nobold" is actually "21;"). But that's not quite enough, as somebody may use both "bold" and "nobold", requiring 5 characters. This wasn't a problem for the final count, because we over-estimated in other ways, but let's clarify how we got to the final number. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--color.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/color.h b/color.h
index 7fe77fb..2d0507f 100644
--- a/color.h
+++ b/color.h
@@ -3,18 +3,20 @@
struct strbuf;
-/* 2 + (2 * num_attrs) + 8 + 1 + 8 + 'm' + NUL */
-/* "\033[1;2;4;5;7;38;5;2xx;48;5;2xxm\0" */
/*
* The maximum length of ANSI color sequence we would generate:
* - leading ESC '[' 2
- * - attr + ';' 3 * 10 (e.g. "1;")
+ * - attr + ';' 2 * num_attr (e.g. "1;")
+ * - no-attr + ';' 3 * num_attr (e.g. "22;")
* - fg color + ';' 17 (e.g. "38;2;255;255;255;")
* - bg color + ';' 17 (e.g. "48;2;255;255;255;")
* - terminating 'm' NUL 2
*
- * The above overcounts attr (we only use 5 not 8) and one semicolon
- * but it is close enough.
+ * The above overcounts by one semicolon but it is close enough.
+ *
+ * The space for attributes is also slightly overallocated, as
+ * the negation for some attributes is the same (e.g., nobold and nodim).
+ * We also allocate space for 6 attributes (even though we have only 5).
*/
#define COLOR_MAXLEN 70