aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/diff.c3
-rw-r--r--editors/patch.c14
-rw-r--r--editors/vi.c8
3 files changed, 18 insertions, 7 deletions
diff --git a/editors/diff.c b/editors/diff.c
index a78a0ee28..c3ad31bf3 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -740,9 +740,10 @@ static int diffreg(char *file[2])
740 unlink(name); 740 unlink(name);
741 if (bb_copyfd_eof(fd, fd_tmp) < 0) 741 if (bb_copyfd_eof(fd, fd_tmp) < 0)
742 xfunc_die(); 742 xfunc_die();
743 if (fd) /* Prevents closing of stdin */ 743 if (fd != STDIN_FILENO)
744 close(fd); 744 close(fd);
745 fd = fd_tmp; 745 fd = fd_tmp;
746 xlseek(fd, 0, SEEK_SET);
746 } 747 }
747 fp[i] = fdopen(fd, "r"); 748 fp[i] = fdopen(fd, "r");
748 } 749 }
diff --git a/editors/patch.c b/editors/patch.c
index 13785ef46..cb25e4140 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -345,6 +345,8 @@ done:
345// state 1: Found +++ file indicator, look for @@ 345// state 1: Found +++ file indicator, look for @@
346// state 2: In hunk: counting initial context lines 346// state 2: In hunk: counting initial context lines
347// state 3: In hunk: getting body 347// state 3: In hunk: getting body
348// Like GNU patch, we don't require a --- line before the +++, and
349// also allow the --- after the +++ line.
348 350
349int patch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 351int patch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
350int patch_main(int argc UNUSED_PARAM, char **argv) 352int patch_main(int argc UNUSED_PARAM, char **argv)
@@ -412,7 +414,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
412 } 414 }
413 415
414 // Open a new file? 416 // Open a new file?
415 if (!strncmp("--- ", patchline, 4) || !strncmp("+++ ", patchline, 4)) { 417 if (is_prefixed_with(patchline, "--- ") || is_prefixed_with(patchline, "+++ ")) {
416 char *s, **name = reverse ? &newname : &oldname; 418 char *s, **name = reverse ? &newname : &oldname;
417 int i; 419 int i;
418 420
@@ -444,7 +446,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
444 446
445 // Start a new hunk? Usually @@ -oldline,oldlen +newline,newlen @@ 447 // Start a new hunk? Usually @@ -oldline,oldlen +newline,newlen @@
446 // but a missing ,value means the value is 1. 448 // but a missing ,value means the value is 1.
447 } else if (state == 1 && !strncmp("@@ -", patchline, 4)) { 449 } else if (state == 1 && is_prefixed_with(patchline, "@@ -")) {
448 int i; 450 int i;
449 char *s = patchline+4; 451 char *s = patchline+4;
450 452
@@ -462,6 +464,14 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
462 TT.context = 0; 464 TT.context = 0;
463 state = 2; 465 state = 2;
464 466
467 // If the --- line is missing or malformed, either oldname
468 // or (for -R) newname could be NULL -- but not both. Like
469 // GNU patch, proceed based on the +++ line, and avoid SEGVs.
470 if (!oldname)
471 oldname = xstrdup("MISSING_FILENAME");
472 if (!newname)
473 newname = xstrdup("MISSING_FILENAME");
474
465 // If this is the first hunk, open the file. 475 // If this is the first hunk, open the file.
466 if (TT.filein == -1) { 476 if (TT.filein == -1) {
467 int oldsum, newsum, empty = 0; 477 int oldsum, newsum, empty = 0;
diff --git a/editors/vi.c b/editors/vi.c
index 1fa97b568..926aef19b 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -2017,8 +2017,7 @@ static char *char_insert(char *p, char c, int undo) // insert the char c at 'p'
2017 p--; 2017 p--;
2018 } 2018 }
2019 } else if (c == erase_char || c == 8 || c == 127) { // Is this a BS 2019 } else if (c == erase_char || c == 8 || c == 127) { // Is this a BS
2020 // 123456789 2020 if (p > text) {
2021 if ((p[-1] != '\n') && (dot>text)) {
2022 p--; 2021 p--;
2023 p = text_hole_delete(p, p, ALLOW_UNDO_QUEUED); // shrink buffer 1 char 2022 p = text_hole_delete(p, p, ALLOW_UNDO_QUEUED); // shrink buffer 1 char
2024 } 2023 }
@@ -4073,8 +4072,9 @@ static void do_cmd(int c)
4073 undo_queue_commit(); 4072 undo_queue_commit();
4074 break; 4073 break;
4075 case KEYCODE_DELETE: 4074 case KEYCODE_DELETE:
4076 c = 'x'; 4075 if (dot < end - 1)
4077 // fall through 4076 dot = yank_delete(dot, dot, 1, YANKDEL, ALLOW_UNDO);
4077 break;
4078 case 'X': // X- delete char before dot 4078 case 'X': // X- delete char before dot
4079 case 'x': // x- delete the current char 4079 case 'x': // x- delete the current char
4080 case 's': // s- substitute the current char 4080 case 's': // s- substitute the current char