threads / patch / 30587

patchfix off-by-one error in split_ident_line

Subject: [PATCH] fix off-by-one error in split_ident_line

## tl;dr

One message between May 22, 2012 and May 22, 2012. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Jeff King· May 22, 2012, 06:12 UTC · lore

Commit 4b340cf split the logic to parse an ident line out of pretty.c's format_person_part. But in doing so, it accidentally introduced an off-by-one error that caused it to think that single-character names were invalid.

This manifested itself as the "%an" format failing to show anything at all for a single-character name.

Reported-by: Brian Turner <bturner@atlassian.com>
Signed-off-by: Jeff King <peff@peff.net>
---
 ident.c                    | 2 +-
 t/t6006-rev-list-format.sh | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
Show changes to 2 files +8 −1

ident.c, t/t6006-rev-list-format.sh

diff --git a/ident.c b/ident.c
index 87c697c..5df094d 100644
--- a/ident.c
+++ b/ident.c
@@ -244,7 +244,7 @@ int split_ident_line(struct ident_split *split, const char *line, int len)
 	if (!split->mail_begin)
 		return status;
 
-	for (cp = split->mail_begin - 2; line < cp; cp--)
+	for (cp = split->mail_begin - 2; line <= cp; cp--)
 		if (!isspace(*cp)) {
 			split->name_end = cp + 1;
 			break;
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index a01d244..f94f0c4 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -283,4 +283,11 @@ test_expect_success 'oneline with empty message' '
 	test_line_count = 5 testg.txt
 '
 
+test_expect_success 'single-character name is parsed correctly' '
+	git commit --author="a <a@example.com>" --allow-empty -m foo &&
+	echo "a <a@example.com>" >expect &&
+	git log -1 --format="%an <%ae>" >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
1.7.9.7.33.gc430a50

← back to recent threads