From 51744efab41bad66ee8e59e85807b5eefcfb30c8 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Fri, 1 Dec 2023 23:20:43 -0500 Subject: [PATCH] fix array-map access on unrecognized key to return default 0 --- src/core/chuck_instr.cpp | 15 +++++---------- src/core/chuck_oo.cpp | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/core/chuck_instr.cpp b/src/core/chuck_instr.cpp index 5f8d23ddb..a0e41e2b7 100644 --- a/src/core/chuck_instr.cpp +++ b/src/core/chuck_instr.cpp @@ -6978,8 +6978,7 @@ void Chuck_Instr_Array_Map_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shre push_( sp, val ); } else { // get the value - if( !arr->get( key->str(), &val ) ) - goto error; + arr->get( key->str(), &val ); // push the value push_( sp, val ); } @@ -7000,8 +6999,7 @@ void Chuck_Instr_Array_Map_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shre push_( sp, val ); } else { // get the value - if( !arr->get( key->str(), &fval ) ) - goto error; + arr->get( key->str(), &fval ); // push the value push_( ((t_CKFLOAT *&)sp), fval ); } @@ -7022,8 +7020,7 @@ void Chuck_Instr_Array_Map_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shre push_( sp, val ); } else { // get the value - if( !arr->get( key->str(), &v2 ) ) - goto error; + arr->get( key->str(), &v2 ); // push the value push_( ((t_CKVEC2 *&)sp), v2 ); } @@ -7044,8 +7041,7 @@ void Chuck_Instr_Array_Map_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shre push_( sp, val ); } else { // get the value - if( !arr->get( key->str(), &v3 ) ) - goto error; + arr->get( key->str(), &v3 ); // push the value push_( ((t_CKVEC3 *&)sp), v3 ); } @@ -7066,8 +7062,7 @@ void Chuck_Instr_Array_Map_Access::execute( Chuck_VM * vm, Chuck_VM_Shred * shre push_( sp, val ); } else { // get the value - if( !arr->get( key->str(), &v4 ) ) - goto error; + arr->get( key->str(), &v4 ); // push the value push_( ((t_CKVEC4 *&)sp), v4 ); } diff --git a/src/core/chuck_oo.cpp b/src/core/chuck_oo.cpp index c18f0f580..83eb2acfd 100644 --- a/src/core/chuck_oo.cpp +++ b/src/core/chuck_oo.cpp @@ -2662,7 +2662,7 @@ t_CKINT Chuck_ArrayVec4::get( t_CKINT i, t_CKVEC4 * val ) t_CKINT Chuck_ArrayVec4::get( const string & key, t_CKVEC4 * val ) { // set to zero - val->x = val->y = val->z = val->w; + val->x = val->y = val->z = val->w = 0; // iterator map::iterator iter = m_map.find( key );