From: fennecdjay Date: Sun, 1 Sep 2019 07:21:27 +0000 (+0200) Subject: :art: Do not use asprintf X-Git-Tag: nightly~2251 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=c645c08c43f698b40ee10b283658a0cdfb30a5b3;p=gwion.git :art: Do not use asprintf --- diff --git a/src/parse/func.c b/src/parse/func.c index 702fa447..63b33ba0 100644 --- a/src/parse/func.c +++ b/src/parse/func.c @@ -48,11 +48,14 @@ ANN Func get_func(const Env env, const Func_Def def) { ANN2(1,2) Symbol func_symbol(const Env env, const m_str nspc, const m_str base, const m_str tmpl, const m_uint i) { - char* name; - CHECK_BO(asprintf(&name, "%s%s%s%s@%" UINT_F "@%s", + const size_t base_len = strlen(base); + const size_t tmpl_len = !tmpl ? 0 : strlen(tmpl) + 2; + const size_t nspc_len = strlen(nspc); + const size_t idx_len = num_digit(i); + const size_t len = base_len + tmpl_len + nspc_len + idx_len + 2; + char name[len + 1]; + CHECK_BO(sprintf(name, "%s%s%s%s@%" UINT_F "@%s", base, !tmpl ? "" : "<", !tmpl ? "" : tmpl, !tmpl ? "" : ">", i, nspc)) - const Symbol sym = insert_symbol(env->gwion->st, name); - free(name); - return sym; + return insert_symbol(env->gwion->st, name); }