diff --git a/b2/subex.c b/b2/subex.c index 77b8cbd..b29ae6c 100644 --- a/b2/subex.c +++ b/b2/subex.c @@ -92,7 +92,7 @@ static char *compose(const struct chunk *c, const char *s, const regmatch_t *match, const char *units) { char *res = stralloc(""); - int res_len = 0, len; + int res_len = 0; const char *val; char *tmp, *tmp2; int n; @@ -118,10 +118,8 @@ static char *compose(const struct chunk *c, } if (match[n].rm_so == -1) break; - len = match[n].rm_eo-match[n].rm_so; - tmp = alloc_size(len); - memcpy(tmp, s+match[n].rm_so, len); - tmp[len] = 0; + tmp = stralloc_n(s+match[n].rm_so, + match[n].rm_eo-match[n].rm_so); tmp2 = canonicalize(tmp, units ? units[n-1] : 0); append(&res, &res_len, tmp2); free(tmp);