Skip to content

Commit 2564aa4

Browse files
sschuberthgitster
authored andcommitted
blame.c: Properly initialize strbuf after calling, textconv_object()
For a plain string where only the length is known, strbuf.alloc needs to be initialized to the length. Otherwise strbuf.alloc is 0 and a later call to strbuf_setlen() will fail. This bug surfaced when calling git blame under Windows on a *.doc file. The *.doc file is converted to plain text by antiword via the textconv mechanism. However, the plain text returned by antiword contains DOS line endings instead of Unix line endings which triggered the strbuf_setlen() which previous to this patch failed. Signed-off-by: Sebastian Schuberth <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9006471 commit 2564aa4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

builtin/blame.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2094,8 +2094,10 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
20942094
switch (st.st_mode & S_IFMT) {
20952095
case S_IFREG:
20962096
if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&
2097-
textconv_object(read_from, mode, null_sha1, &buf.buf, &buf_len))
2097+
textconv_object(read_from, mode, null_sha1, &buf.buf, &buf_len)) {
2098+
buf.alloc = buf_len;
20982099
buf.len = buf_len;
2100+
}
20992101
else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
21002102
die_errno("cannot open or read '%s'", read_from);
21012103
break;

0 commit comments

Comments
 (0)