aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-01-23 05:13:15 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2016-01-23 05:13:15 +0100
commiteb5091070f6876993d868d2b2bb49b4b4d3ed002 (patch)
treefd8633a0b0379c4932012a6625499994b0b2dd63 /editors
parentc7e47cf6273830a59f5d3f822e4a6855a80312c6 (diff)
downloadbusybox-eb5091070f6876993d868d2b2bb49b4b4d3ed002.tar.gz
patch: correctly handle "patch FILE_TO_PATCH" form. Closes 7736
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/patch.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/editors/patch.c b/editors/patch.c
index cb25e4140..988021d77 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -372,10 +372,6 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
xmove_fd(xopen_stdin(argv[1]), STDIN_FILENO);
}
}
- if (argv[0]) {
- oldname = xstrdup(argv[0]);
- newname = xstrdup(argv[0]);
- }
// Loop through the lines in the patch
for(;;) {
@@ -486,10 +482,10 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
// or if new hunk is empty (zero context) after patching
if (!strcmp(name, "/dev/null") || !(reverse ? oldsum : newsum)) {
name = reverse ? newname : oldname;
- empty++;
+ empty = 1;
}
- // handle -p path truncation.
+ // Handle -p path truncation.
for (i = 0, s = name; *s;) {
if ((option_mask32 & FLAG_PATHLEN) && TT.prefix == i)
break;
@@ -500,6 +496,9 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
i++;
name = s;
}
+ // If "patch FILE_TO_PATCH", completely ignore name from patch
+ if (argv[0])
+ name = argv[0];
if (empty) {
// File is empty after the patches have been applied