From b1c4b7249a33098ca7f2e8f2b786e969493dddcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sun, 10 Jan 2016 12:32:04 +0100 Subject: Simplify code by using text_bytes_alloc0 --- text-regex.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'text-regex.c') 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; -- cgit v1.2.3