From da97fb5b179ad6cc825d0b8900d7c9396ce9bcf9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 27 Nov 2019 00:47:36 +0100 Subject: [PATCH] :art: Coverity fixes --- ast | 2 +- src/import/cdef.c | 2 +- src/import/oper.c | 2 +- src/import/type.c | 15 +++++++++++---- src/import/udef.c | 7 ++----- src/lib/tuple.c | 3 ++- src/plug.c | 6 +++--- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/ast b/ast index 0c6c6dcd..1bf20cad 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 0c6c6dcd949db0aeb7f292c22411381fb68624f5 +Subproject commit 1bf20cade4401334d94195cd9b245743a1ba096e diff --git a/src/import/cdef.c b/src/import/cdef.c index abf8d2ec..eddfa296 100644 --- a/src/import/cdef.c +++ b/src/import/cdef.c @@ -60,7 +60,7 @@ ANN static Type type_finish(const Gwi gwi, const Type t) { ANN2(1,2) Type gwi_class_ini(const Gwi gwi, const m_str name, const m_str parent) { struct ImportCK ck = { .name=name }; CHECK_BO(check_typename_def(gwi, &ck)) - Type_Decl *td = str2decl(gwi, parent ?: "Object"); // check + DECL_OO(Type_Decl *,td, = str2decl(gwi, parent ?: "Object")) Tmpl* tmpl = ck.tmpl ? new_tmpl_base(gwi->gwion->mp, ck.tmpl) : NULL; if(tmpl) template_push_types(gwi->gwion->env, tmpl); diff --git a/src/import/oper.c b/src/import/oper.c index b9571708..7e280453 100644 --- a/src/import/oper.c +++ b/src/import/oper.c @@ -20,7 +20,7 @@ ANN static Type _get_type(const Gwi gwi, const m_str str) { if(str == (m_str)OP_ANY_TYPE) return OP_ANY_TYPE; struct array_checker ck = { .str=str }; - const ID_List list = ck2list(gwi, &ck); + DECL_OO(const ID_List, list, = ck2list(gwi, &ck)) const Type t = find_type(gwi->gwion->env, list); if(list) free_id_list(gwi->gwion->mp, list); diff --git a/src/import/type.c b/src/import/type.c index af6e68e0..2e9e4c0d 100644 --- a/src/import/type.c +++ b/src/import/type.c @@ -14,17 +14,24 @@ #include "import.h" #include "gwi.h" -ANN2(1,2) Type gwi_mk_type(const Gwi gwi NUSED, const m_str name, const m_uint size, const m_str parent_name) { - CHECK_OO(str2sym(gwi, name)) +ANN2(1) static Type get_parent(const Gwi gwi, const m_str parent_name) { Type_Decl* td = parent_name ? str2decl(gwi, parent_name) : NULL; if(td) { if(td->array || td->types) { + const m_str str = td->array ? "array" : "template"; free_type_decl(gwi->gwion->mp, td); - GWI_ERR_O(_("can't use gwi_mk_type to extend %s types"), - td->array ? "array" : "template") + GWI_ERR_O(_("can't use gwi_mk_type to extend %s types"), str) } } const Type parent = td ? known_type(gwi->gwion->env, td) : NULL; + if(td) + free_type_decl(gwi->gwion->mp, td); + return parent; +} + +ANN2(1,2) Type gwi_mk_type(const Gwi gwi, const m_str name, const m_uint size, const m_str parent_name) { + CHECK_OO(str2sym(gwi, name)) + const Type parent = get_parent(gwi, parent_name); const Type t = new_type(gwi->gwion->mp, 0, name, parent); t->size = size; return t; diff --git a/src/import/udef.c b/src/import/udef.c index 2b052f62..4f5e2276 100644 --- a/src/import/udef.c +++ b/src/import/udef.c @@ -63,16 +63,14 @@ ANN Type gwi_union_end(const Gwi gwi, const ae_flag flag) { CHECK_BO(ck_ok(gwi, ck_udef)) if(!gwi->ck->list) GWI_ERR_O(_("union is empty")); + if(gwi->ck->tmpl && gwi->ck->xid) + GWI_ERR_O(_("Template union type can't declare instance at declaration")); const Union_Def udef = new_union_def(gwi->gwion->mp, gwi->ck->list, loc(gwi)); gwi->ck->list = NULL; udef->flag = flag; udef->xid = gwi->ck->xid; udef->type_xid = gwi->ck->sym; -// udef->xid = gwi->ck->sym; -// udef->type_xid = gwi->ck->xid; if(gwi->ck->tmpl) { - if(udef->xid) - GWI_ERR_O(_("Template union type can't declare instance at declaration")); udef->tmpl = gwi_tmpl(gwi); gwi->ck->tmpl = NULL; } @@ -88,5 +86,4 @@ ANN void ck_clean_udef(MemPool mp, ImportCK* ck) { free_decl_list(mp, ck->list); if(ck->tmpl) free_id_list(mp, ck->tmpl); -// do we miss ck->td ? } diff --git a/src/lib/tuple.c b/src/lib/tuple.c index 994007dc..be60b754 100644 --- a/src/lib/tuple.c +++ b/src/lib/tuple.c @@ -140,8 +140,9 @@ static OP_CHECK(opck_at_tuple) { e->d.exp_decl.td->xid->xid = insert_symbol(t->name); const Exp next = e->next; e->next = NULL; - CHECK_BO(traverse_exp(env, e)) + const m_bool ret = traverse_exp(env, e); e->next = next; + CHECK_BO(ret) bin->rhs->meta = ae_meta_var; } ++i; diff --git a/src/plug.c b/src/plug.c index dbfd0452..d3a626fd 100644 --- a/src/plug.c +++ b/src/plug.c @@ -84,9 +84,9 @@ ANN static inline m_str plug_name(struct PlugHandle *h) { } ANN static void plug_get(struct PlugHandle *h, const m_str c) { - void* dl = DLOPEN(c, RTLD_LAZY | RTLD_GLOBAL); - if(dl) { - vector_add(&h->pi->vec[GWPLUG_DL], (vtype)dl); + h->dl = DLOPEN(c, RTLD_LAZY | RTLD_GLOBAL); + if(h->dl) { + vector_add(&h->pi->vec[GWPLUG_DL], (vtype)h->dl); h->name = plug_name(h); plug_import(h); plug_module(h); -- 2.43.0