aboutsummaryrefslogtreecommitdiff
path: root/text-regex.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-01-10 12:32:04 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-01-10 12:45:58 +0100
commitb1c4b7249a33098ca7f2e8f2b786e969493dddcf (patch)
tree1a9db1a93281d5b4a8ccef3a68c9a1fb447cda73 /text-regex.c
parente6e077c8469f857ac58d804c788e887ce86e2303 (diff)
downloadvis-b1c4b7249a33098ca7f2e8f2b786e969493dddcf.tar.gz
vis-b1c4b7249a33098ca7f2e8f2b786e969493dddcf.tar.xz
Simplify code by using text_bytes_alloc0
Diffstat (limited to 'text-regex.c')
-rw-r--r--text-regex.c8
1 files changed, 2 insertions, 6 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;