aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/vi.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 7f1d27fdf..7f5f2dcbc 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -662,7 +662,7 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present
662 c = c - 'a'; 662 c = c - 'a';
663 q = mark[(unsigned char) c]; 663 q = mark[(unsigned char) c];
664 if (q != NULL) { // is mark valid 664 if (q != NULL) { // is mark valid
665 *addr = count_lines(text, q); // count lines 665 *addr = count_lines(text, q);
666 } 666 }
667 } 667 }
668 } 668 }
@@ -1673,12 +1673,16 @@ static char *char_insert(char *p, char c) // insert the char c at 'p'
1673 } 1673 }
1674 if (autoindent && c == '\n') { // auto indent the new line 1674 if (autoindent && c == '\n') { // auto indent the new line
1675 char *q; 1675 char *q;
1676 1676 size_t len;
1677 q = prev_line(p); // use prev line as template 1677 q = prev_line(p); // use prev line as template
1678 for (; isblank(*q); q++) { 1678 len = strspn(q, " \t"); // space or tab
1679 uintptr_t bias = stupid_insert(p, *q); // insert the char 1679 if (len) {
1680 p += bias + 1; 1680 uintptr_t bias;
1681 bias = text_hole_make(p, len);
1682 p += bias;
1681 q += bias; 1683 q += bias;
1684 memcpy(p, q, len);
1685 p += len;
1682 } 1686 }
1683 } 1687 }
1684#endif 1688#endif
@@ -2042,7 +2046,7 @@ static uintptr_t string_insert(char *p, const char *s) // insert the string at '
2042 i = strlen(s); 2046 i = strlen(s);
2043 bias = text_hole_make(p, i); 2047 bias = text_hole_make(p, i);
2044 p += bias; 2048 p += bias;
2045 strncpy(p, s, i); 2049 memcpy(p, s, i);
2046#if ENABLE_FEATURE_VI_YANKMARK 2050#if ENABLE_FEATURE_VI_YANKMARK
2047 { 2051 {
2048 int cnt; 2052 int cnt;
@@ -2060,21 +2064,13 @@ static uintptr_t string_insert(char *p, const char *s) // insert the string at '
2060#if ENABLE_FEATURE_VI_YANKMARK 2064#if ENABLE_FEATURE_VI_YANKMARK
2061static char *text_yank(char *p, char *q, int dest) // copy text into a register 2065static char *text_yank(char *p, char *q, int dest) // copy text into a register
2062{ 2066{
2063 char *t; 2067 int cnt = q - p;
2064 int cnt; 2068 if (cnt < 0) { // they are backwards- reverse them
2065 2069 p = q;
2066 if (q < p) { // they are backwards- reverse them 2070 cnt = -cnt;
2067 t = q;
2068 q = p;
2069 p = t;
2070 } 2071 }
2071 cnt = q - p + 1; 2072 free(reg[dest]); // if already a yank register, free it
2072 t = reg[dest]; 2073 reg[dest] = xstrndup(p, cnt + 1);
2073 free(t); // if already a yank register, free it
2074 t = xmalloc(cnt + 1); // get a new register
2075 memset(t, '\0', cnt + 1); // clear new text[]
2076 strncpy(t, p, cnt); // copy text[] into bufer
2077 reg[dest] = t;
2078 return p; 2074 return p;
2079} 2075}
2080 2076
@@ -3115,7 +3111,7 @@ static void do_cmd(int c)
3115 case 'P': // P- Put register before 3111 case 'P': // P- Put register before
3116 case 'p': // p- put register after 3112 case 'p': // p- put register after
3117 p = reg[YDreg]; 3113 p = reg[YDreg];
3118 if (p == 0) { 3114 if (p == NULL) {
3119 status_line_bold("Nothing in register %c", what_reg()); 3115 status_line_bold("Nothing in register %c", what_reg());
3120 break; 3116 break;
3121 } 3117 }