From 9681d44ca486596cd97b2e2b2511ed8adeb6f7cd Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 20 May 2012 20:57:18 -0300 Subject: [PATCH] b2/subst.c: use vstring for modified regexp --- b2/subst.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/b2/subst.c b/b2/subst.c index 1b8ae36..fea65ef 100644 --- a/b2/subst.c +++ b/b2/subst.c @@ -19,6 +19,7 @@ #include #include "util.h" +#include "vstring.h" #include "lang.h" #include "subst.h" @@ -37,21 +38,28 @@ static struct subst *alloc_subst(enum subst_type type) } +static char *prepare_re(const char *re) +{ + char *res = NULL; + int res_len = 0; + + append_char(&res, &res_len, '^'); + append(&res, &res_len, re); + append_char(&res, &res_len, '$'); + return res; +} + + struct subst *subst_match(const char *src, const char *re) { char error[1000]; struct subst *sub; char *tmp; - int err, len; + int err; sub = alloc_subst(st_match); sub->u.match.src = src; - len = strlen(re); - tmp = alloc_size(len+3); - tmp[0] = '^'; - memcpy(tmp+1, re, len); - tmp[len+1] = '$'; - tmp[len+2] = 0; + tmp = prepare_re(re); err = regcomp(&sub->u.match.re, tmp, REG_EXTENDED); free(tmp); if (err) {