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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Apr 17, 2013 at 20:33 UTC
de5abe9fe91a496d019d62abefe23df9d72fad30
1 file changed
+8
-3
builtin/blame.c
+8
-3
@@ -1375,10 +1375,15 @@ static void get_ac_line(const char *inbuf, const char *what,
1375
maillen = ident.mail_end - ident.mail_begin;
1376
mailbuf = ident.mail_begin;
1377
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;
1382
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)");
1387
1388
/*
1389
* Now, convert both name and e-mail using mailmap