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 <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Torvalds committed
Dec 17, 2008 at 10:26 UTC
cf219d8c68ada1aa2855f4862f15753a32d09641
1 file changed
+7
-9
diff.c
+7
-9
@@ -1773,19 +1773,17 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
1773
s->size = xsize_t(st.st_size);
1774
if (!s->size)
1775
goto empty;
1776
- if (size_only)
1777
- return 0;
1776
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))
1780
goto err_empty;
1786
- }
1781
+ s->data = strbuf_detach(&sb, &s->size);
1782
+ s->should_free = 1;
1783
return 0;
1784
}
1785
+ if (size_only)
1786
+ return 0;
1787
fd = open(s->path, O_RDONLY);
1788
if (fd < 0)
1789
goto err_empty;