Skip to content

Commit de5abe9

Browse files
René Scharfegitster
authored andcommitted
blame: handle broken commit headers gracefully
split_ident_line() can leave us with the pointers date_begin, date_end, tz_begin and tz_end all set to NULL. Check them before use and supply the same fallback values as in the case of a negative return code from split_ident_line(). The "(unknown)" is not actually shown in the output, though, because it will be converted to a number (zero) eventually. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9dbe7c3 commit de5abe9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

builtin/blame.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,10 +1375,15 @@ static void get_ac_line(const char *inbuf, const char *what,
13751375
maillen = ident.mail_end - ident.mail_begin;
13761376
mailbuf = ident.mail_begin;
13771377

1378-
*time = strtoul(ident.date_begin, NULL, 10);
1378+
if (ident.date_begin && ident.date_end)
1379+
*time = strtoul(ident.date_begin, NULL, 10);
1380+
else
1381+
*time = 0;
13791382

1380-
len = ident.tz_end - ident.tz_begin;
1381-
strbuf_add(tz, ident.tz_begin, len);
1383+
if (ident.tz_begin && ident.tz_end)
1384+
strbuf_add(tz, ident.tz_begin, ident.tz_end - ident.tz_begin);
1385+
else
1386+
strbuf_addstr(tz, "(unknown)");
13821387

13831388
/*
13841389
* Now, convert both name and e-mail using mailmap

0 commit comments

Comments
 (0)