From 8c77f35d366f412cd44f3f5d84677f99ceb2261f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 4 May 2020 23:27:05 +0200 Subject: [PATCH] :art: Secure get_type_name --- include/env/type.h | 3 +-- src/env/type.c | 3 ++- src/lib/ptr.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/env/type.h b/include/env/type.h index 5f4ce826..ea029742 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -28,9 +28,8 @@ struct Type_ { ANN2(1,3) ANEW Type new_type(MemPool, const m_uint xid, const m_str name, const Type); ANEW ANN Type type_copy(MemPool, const Type type); -ANN m_str get_type_name(const Env, const m_str, const m_uint); +ANN m_str get_type_name(const Env, const Type t, const m_uint); ANN Value find_value(const Type, const Symbol); -//ANN Func find_func(const Type, const Symbol); ANN m_bool isa(const Type, const Type) __attribute__((pure)); ANN m_bool isres(const Env, const Symbol, const loc_t pos); ANN Type array_type(const Env, const Type, const m_uint); diff --git a/src/env/type.c b/src/env/type.c index 564e8f17..e12ae708 100644 --- a/src/env/type.c +++ b/src/env/type.c @@ -136,7 +136,8 @@ ANN m_bool type_ref(Type t) { return 0; } -ANN m_str get_type_name(const Env env, const m_str s, const m_uint index) { +ANN m_str get_type_name(const Env env, const Type t, const m_uint index) { + const m_str s = t->name; m_str name = strstr(s, "<"); m_uint i = 0; m_uint lvl = 0; diff --git a/src/lib/ptr.c b/src/lib/ptr.c index c3e78c55..e4b43154 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -30,7 +30,7 @@ static OP_CHECK(opck_ptr_assign) { do { Type u = bin->rhs->info->type; do { - const m_str str = get_type_name(env, u->name, 1); + const m_str str = get_type_name(env, u, 1); if(str && !strcmp(t->name, str)) return bin->lhs->info->type; } while((u = u->e->parent)); @@ -46,7 +46,7 @@ static INSTR(instr_ptr_assign) { static OP_CHECK(opck_ptr_deref) { const Exp_Unary* unary = (Exp_Unary*)data; - DECL_ON(const m_str, str, = get_type_name(env, unary->exp->info->type->name, 1)) + DECL_ON(const m_str, str, = get_type_name(env, unary->exp->info->type, 1)) return exp_self(unary)->info->type = nspc_lookup_type1(env->curr, insert_symbol(str)); } @@ -66,8 +66,8 @@ static OP_CHECK(opck_ptr_cast) { static OP_CHECK(opck_ptr_implicit) { const struct Implicit* imp = (struct Implicit*)data; const Exp e = imp->e; - DECL_OO(const m_str, name, = get_type_name(env, imp->t->name, 1)) - if(!strcmp(get_type_name(env, imp->t->name, 1), e->info->type->name)) { + DECL_OO(const m_str, name, = get_type_name(env, imp->t, 1)) + if(!strcmp(get_type_name(env, imp->t, 1), e->info->type->name)) { const m_str access = exp_access(e); if(access) ERR_N(e->pos, _("can't cast %s value to Ptr"), access); -- 2.43.0