[PATCH 3/5] graph: fix extra spaces in graph_padding_line

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The graph_padding_line() function outputs a series of "|"
columns, and then pads with spaces to graph->width by
calling graph_pad_horizontally(). However, we tell the
latter that we wrote graph->num_columns characters, which is
not true; we also needed spaces between the columns. Let's
keep a count of how many characters we've written, which is
what all the other callers of graph_pad_horizontally() do.

Without this, any output that is written at the end of a
padding line will be bumped out by at least an extra
graph->num_columns spaces. Presumably nobody ever noticed
the bug because there's no code path that actually writes to
the end of a padding line.

Signed-off-by: Jeff King <peff@xxxxxxxx>
---
 graph.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/graph.c b/graph.c
index 06f1139..d4e8519 100644
--- a/graph.c
+++ b/graph.c
@@ -1175,6 +1175,7 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)
 static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
 {
 	int i;
+	int chars_written = 0;
 
 	if (graph->state != GRAPH_COMMIT) {
 		graph_next_line(graph, sb);
@@ -1190,14 +1191,21 @@ static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
 	 */
 	for (i = 0; i < graph->num_columns; i++) {
 		struct column *col = &graph->columns[i];
+
 		strbuf_write_column(sb, col, '|');
-		if (col->commit == graph->commit && graph->num_parents > 2)
-			strbuf_addchars(sb, ' ', (graph->num_parents - 2) * 2);
-		else
+		chars_written++;
+
+		if (col->commit == graph->commit && graph->num_parents > 2) {
+			int len = (graph->num_parents - 2) * 2;
+			strbuf_addchars(sb, ' ', len);
+			chars_written += len;
+		} else {
 			strbuf_addch(sb, ' ');
+			chars_written++;
+		}
 	}
 
-	graph_pad_horizontally(graph, sb, graph->num_columns);
+	graph_pad_horizontally(graph, sb, chars_written);
 
 	/*
 	 * Update graph->prev_state since we have output a padding line
-- 
2.10.0.566.g5365f87




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]