From db279b79203c2ef0f186c19f9f727aecb5324367 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 23 May 2012 14:18:02 -0300 Subject: [PATCH] b2/subex.c (compose): use stralloc_n instead of open-coding its functionality --- b2/subex.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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);