From c645c08c43f698b40ee10b283658a0cdfb30a5b3 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sun, 1 Sep 2019 09:21:27 +0200 Subject: [PATCH] :art: Do not use asprintf --- src/parse/func.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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); } -- 2.43.0