Skip to content

Commit 912342d

Browse files
committed
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 <[email protected]> Acked-by: Linus Torvalds <[email protected]>
1 parent edfd45d commit 912342d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

combine-diff.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -703,15 +703,15 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
703703
goto deleted_file;
704704

705705
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) {
710709
error("readlink(%s): %s", elem->path,
711710
strerror(errno));
712711
return;
713712
}
714-
result[len] = 0;
713+
result_size = buf.len;
714+
result = strbuf_detach(&buf, NULL);
715715
elem->mode = canon_mode(st.st_mode);
716716
}
717717
else if (0 <= (fd = open(elem->path, O_RDONLY)) &&

0 commit comments

Comments
 (0)