Skip to content

Commit cf219d8

Browse files
torvaldsgitster
authored andcommitted
Make 'diff_populate_filespec()' use the new 'strbuf_readlink()'
This makes all tests pass on a system where 'lstat()' has been hacked to return bogus data in st_size for symlinks. Of course, the test coverage isn't complete, but it's a good baseline. Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b760d3a commit cf219d8

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

diff.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,19 +1773,17 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
17731773
s->size = xsize_t(st.st_size);
17741774
if (!s->size)
17751775
goto empty;
1776-
if (size_only)
1777-
return 0;
17781776
if (S_ISLNK(st.st_mode)) {
1779-
int ret;
1780-
s->data = xmalloc(s->size);
1781-
s->should_free = 1;
1782-
ret = readlink(s->path, s->data, s->size);
1783-
if (ret < 0) {
1784-
free(s->data);
1777+
struct strbuf sb = STRBUF_INIT;
1778+
1779+
if (strbuf_readlink(&sb, s->path, s->size))
17851780
goto err_empty;
1786-
}
1781+
s->data = strbuf_detach(&sb, &s->size);
1782+
s->should_free = 1;
17871783
return 0;
17881784
}
1785+
if (size_only)
1786+
return 0;
17891787
fd = open(s->path, O_RDONLY);
17901788
if (fd < 0)
17911789
goto err_empty;

0 commit comments

Comments
 (0)