diff options
| -rw-r--r-- | text-regex.c | 8 | ||||
| -rw-r--r-- | ui-curses.c | 7 | ||||
| -rw-r--r-- | vis-motions.c | 8 |
3 files changed, 4 insertions, 19 deletions
diff --git a/text-regex.c b/text-regex.c index cff8587..dbaa5fc 100644 --- a/text-regex.c +++ b/text-regex.c @@ -32,11 +32,9 @@ void text_regex_free(Regex *r) { } int text_search_range_forward(Text *txt, size_t pos, size_t len, Regex *r, size_t nmatch, RegexMatch pmatch[], int eflags) { - char *buf = malloc(len + 1); + char *buf = text_bytes_alloc0(txt, pos, len); if (!buf) return REG_NOMATCH; - len = text_bytes_get(txt, pos, len, buf); - buf[len] = '\0'; regmatch_t match[nmatch]; int ret = regexec(&r->regex, buf, nmatch, match, eflags); if (!ret) { @@ -50,11 +48,9 @@ int text_search_range_forward(Text *txt, size_t pos, size_t len, Regex *r, size_ } int text_search_range_backward(Text *txt, size_t pos, size_t len, Regex *r, size_t nmatch, RegexMatch pmatch[], int eflags) { - char *buf = malloc(len + 1); + char *buf = text_bytes_alloc0(txt, pos, len); if (!buf) return REG_NOMATCH; - len = text_bytes_get(txt, pos, len, buf); - buf[len] = '\0'; regmatch_t match[nmatch]; char *cur = buf; int ret = REG_NOMATCH; diff --git a/ui-curses.c b/ui-curses.c index a9ae5f9..0bfd9d8 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -988,12 +988,7 @@ static char *ui_prompt_input(Ui *ui) { if (!uic->prompt_win) return NULL; Text *text = vis_file_text(uic->prompt_win->file); - char *buf = malloc(text_size(text) + 1); - if (!buf) - return NULL; - size_t len = text_bytes_get(text, 0, text_size(text), buf); - buf[len] = '\0'; - return buf; + return text_bytes_alloc0(text, 0, text_size(text)); } static void ui_prompt_hide(Ui *ui) { diff --git a/vis-motions.c b/vis-motions.c index 754b132..8c2146f 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -10,13 +10,7 @@ static char *get_word_at(Text *txt, size_t pos) { Filerange word = text_object_word(txt, pos); if (!text_range_valid(&word)) return NULL; - size_t len = word.end - word.start; - char *buf = malloc(len+1); - if (!buf) - return NULL; - len = text_bytes_get(txt, word.start, len, buf); - buf[len] = '\0'; - return buf; + return text_bytes_alloc0(txt, word.start, word.end - word.start); } /** motion implementations */ |
