Skip to content

Commit 0111681

Browse files
peffgitster
authored andcommitted
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>
1 parent 7654286 commit 0111681

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

color.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33

44
struct strbuf;
55

6-
/* 2 + (2 * num_attrs) + 8 + 1 + 8 + 'm' + NUL */
7-
/* "\033[1;2;4;5;7;38;5;2xx;48;5;2xxm\0" */
86
/*
97
* The maximum length of ANSI color sequence we would generate:
108
* - leading ESC '[' 2
11-
* - attr + ';' 3 * 10 (e.g. "1;")
9+
* - attr + ';' 2 * num_attr (e.g. "1;")
10+
* - no-attr + ';' 3 * num_attr (e.g. "22;")
1211
* - fg color + ';' 17 (e.g. "38;2;255;255;255;")
1312
* - bg color + ';' 17 (e.g. "48;2;255;255;255;")
1413
* - terminating 'm' NUL 2
1514
*
16-
* The above overcounts attr (we only use 5 not 8) and one semicolon
17-
* but it is close enough.
15+
* The above overcounts by one semicolon but it is close enough.
16+
*
17+
* The space for attributes is also slightly overallocated, as
18+
* the negation for some attributes is the same (e.g., nobold and nodim).
19+
* We also allocate space for 6 attributes (even though we have only 5).
1820
*/
1921
#define COLOR_MAXLEN 70
2022

0 commit comments

Comments
 (0)