@matheusbsbs / matheus-bagliano / commits / 912342d9d6
Fork 0

combine-diff.c: use strbuf_readlink()

When showing combined diff using work tree contents, use strbuf_readlink() to read symbolic links. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Linus Torvalds <torvalds@linux-foundation.org>

Junio C Hamano committed Dec 17, 2008 at 12:37 UTC 912342d9d69a30e49491f3fd4d3aa8dc2f6050f3
1 file changed +5 -5
combine-diff.c
+5 -5
@@ -703,15 +703,15 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
703 goto deleted_file;
704
705 if (S_ISLNK(st.st_mode)) {
706 - size_t len = xsize_t(st.st_size);
707 - result_size = len;
708 - result = xmalloc(len + 1);
709 - if (result_size != readlink(elem->path, result, len)) {
706 + struct strbuf buf = STRBUF_INIT;
707 +
708 + if (strbuf_readlink(&buf, elem->path, st.st_size) < 0) {
709 error("readlink(%s): %s", elem->path,
710 strerror(errno));
711 return;
712 }
714 - result[len] = 0;
713 + result_size = buf.len;
714 + result = strbuf_detach(&buf, NULL);
715 elem->mode = canon_mode(st.st_mode);
716 }
717 else if (0 <= (fd = open(elem->path, O_RDONLY)) &&