From a4ab43b4c8c25fc4440122881657ba738b83b48b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Thu, 22 Apr 2021 13:26:18 +0200 Subject: [PATCH] :art: Return after handle() --- plug | 2 +- src/lib/array.c | 4 +++- src/lib/instr.c | 17 ++++++++++------- src/lib/modules.c | 12 +++++++++--- src/lib/ptr.c | 4 +++- src/lib/string.c | 4 +++- src/lib/ugen.c | 1 + src/lib/vararg.c | 4 +++- 8 files changed, 33 insertions(+), 15 deletions(-) diff --git a/plug b/plug index cef9b411..88fdb929 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit cef9b411504a524d73b2e282de45bbd30fd22751 +Subproject commit 88fdb929584524f29d8eeb23b0fc7afd80fd57ee diff --git a/src/lib/array.c b/src/lib/array.c index 92f7b4a8..1f8d9180 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -328,8 +328,10 @@ static INSTR(ArraySlice) { end = ARRAY_LEN(in) + end; const m_int op = start < end ? 1 : -1; const m_uint sz = op > 0 ? end - start : start - end; - if(bounds(in, start) < 0 || bounds(in, end) < 0) + if(bounds(in, start) < 0 || bounds(in, end) < 0) { handle(shred, "OutOfBoundsArraySliceException"); + return; + } const M_Object out = new_array(shred->info->vm->gwion->mp, array->type_ref, sz); for(m_int i = start, j = 0; i != end; i += op, ++j) { m_bit buf[ARRAY_SIZE(in)]; diff --git a/src/lib/instr.c b/src/lib/instr.c index cd362e7f..97babcb4 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -55,12 +55,14 @@ ANN static Func_Def traverse_tmpl(const Emitter emit, struct dottmpl_ *const dt, INSTR(GTmpl) { struct dottmpl_ *dt = (struct dottmpl_*)instr->m_val; const Func f = *(Func*)REG(-SZ_INT); - if(!f) + if(!f) { handle(shred, "EmptyFuncPointerException"); -if(f->code) { - *(VM_Code*)(shred->reg -SZ_INT) = f->code; - return; -} + return; + } + if(f->code) { + *(VM_Code*)(shred->reg -SZ_INT) = f->code; + return; + } const m_str name = f->name; const Emitter emit = shred->info->vm->gwion->emit; emit->env->name = "runtime"; @@ -80,9 +82,10 @@ if(f->code) { free_mstr(emit->gwion->mp, tmpl_name); dt->def = f->def; const Func_Def def = traverse_tmpl(emit, dt, f->value_ref->from->owner); - if(!def) + if(def) + *(VM_Code*)(shred->reg -SZ_INT) = def->base->func->code; + else handle(shred, "MissigTmplPtrException"); - *(VM_Code*)(shred->reg -SZ_INT) = def->base->func->code; } INSTR(DotTmpl) { diff --git a/src/lib/modules.c b/src/lib/modules.c index 92cd7ee4..3b293ffe 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -247,15 +247,21 @@ static INSTR(UsrUGenTick) { const m_uint offset = !instr->m_val ? SZ_INT : 0; shred->reg -= SZ_INT*2 - offset; const M_Object o = *(M_Object*)(shred->reg + SZ_INT - offset); - if(!o) + if(!o) { handle(shred, "NullPtrException"); + return; + } struct UUGen_ *uu = UGEN(o)->module.gen.data; - if(uu->shred) + if(uu->shred) { free_vm_shred(uu->shred); + return; + } UGEN(o)->module.gen.tick = usrugen_tick; const VM_Code code = *(VM_Code*)(shred->reg-offset); - if(!code) + if(!code) { handle(shred, "NullTickException"); + return; + } uu->shred = new_vm_shred(shred->info->vm->gwion->mp, *(VM_Code*)(shred->reg-offset)); vmcode_addref(*(VM_Code*)(shred->reg - offset)); uu->shred->info->vm = shred->info->vm; diff --git a/src/lib/ptr.c b/src/lib/ptr.c index 81585305..db362037 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -89,8 +89,10 @@ static OP_CHECK(opck_ptr_implicit) { static INSTR(instr_ptr_deref) { const m_bit *o = *(m_bit**)REG(-SZ_INT); - if(!o) + if(!o) { handle(shred, _("EmptyPointerException")); + return; + } if(instr->m_val2) memcpy(REG(-SZ_INT), &o, SZ_INT); else { diff --git a/src/lib/string.c b/src/lib/string.c index 63e96112..91deae64 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -83,8 +83,10 @@ static INSTR(StringSlice) { m_int end = *(m_uint*)REG(SZ_INT); if(end < 0) end = strsz + end; - if(bounds(str, start) < 0 || bounds(str, end) < 0) + if(bounds(str, start) < 0 || bounds(str, end) < 0) { handle(shred, "OutOfBoundsStringSlice"); + return; + } const m_int op = start < end ? 1 : -1; const m_uint sz = op > 0 ? end - start : start - end; char c[sz + 1]; diff --git a/src/lib/ugen.c b/src/lib/ugen.c index cc94d445..9908ea12 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -186,6 +186,7 @@ ANN void ugen_disconnect(const restrict UGen lhs, const restrict UGen rhs) { if(!UGEN(rhs)->module.gen.trig) { \ release_connect(shred); \ handle(shred, "NonTriggerException"); \ + return; \ } #define describe_connect_instr(name, func, tgt, opt) \ static INSTR(name##func) { \ diff --git a/src/lib/vararg.c b/src/lib/vararg.c index c6e38455..fe4d086b 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -107,8 +107,10 @@ static OP_CHECK(opck_vararg_cast) { static INSTR(VarargCast) { const M_Object o = *(M_Object*)REG(-SZ_INT); - if(!*(m_uint*)(o->data + SZ_INT)) + if(!*(m_uint*)(o->data + SZ_INT)) { handle(shred, "Using Vararg outside varloop"); + return; + } struct Vararg_* arg = *(struct Vararg_**)o->data; const Type t = (Type)instr->m_val, u = (Type)vector_at(&arg->t, *(m_uint*)(o->data + SZ_INT*4)); -- 2.43.0