[git commit] diff: fix a bug in diffing against stdin. Closes 7784

Denys Vlasenko vda.linux at googlemail.com
Sun Jan 11 15:41:54 UTC 2015


commit: http://git.busybox.net/busybox/commit/?id=39f017293a047ac1063c84263d4d855b86c62ba1
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 editors/diff.c       |    3 ++-
 testsuite/diff.tests |   11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/editors/diff.c b/editors/diff.c
index a78a0ee..c3ad31b 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -740,9 +740,10 @@ static int diffreg(char *file[2])
 			unlink(name);
 			if (bb_copyfd_eof(fd, fd_tmp) < 0)
 				xfunc_die();
-			if (fd) /* Prevents closing of stdin */
+			if (fd != STDIN_FILENO)
 				close(fd);
 			fd = fd_tmp;
+			xlseek(fd, 0, SEEK_SET);
 		}
 		fp[i] = fdopen(fd, "r");
 	}
diff --git a/testsuite/diff.tests b/testsuite/diff.tests
index 6de4648..84d8538 100755
--- a/testsuite/diff.tests
+++ b/testsuite/diff.tests
@@ -44,6 +44,17 @@ testing "diff of stdin, twice" \
 	"" \
 	"stdin"
 
+testing "diff of empty file against stdin" \
+	"diff -u - input | $TRIM_TAB" \
+"\
+--- -
++++ input
+@@ -1 +0,0 @@
+-a
+" \
+	"" \
+	"a\n"
+
 testing "diff of empty file against nonempty one" \
 	"diff -u - input | $TRIM_TAB" \
 "\


More information about the busybox-cvs mailing list