Skip to content

Commit

Permalink
fix array-map access on unrecognized key to return default 0
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Dec 2, 2023
1 parent 0fe3f96 commit 51744ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
15 changes: 5 additions & 10 deletions src/core/chuck_instr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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 );
}
Expand All @@ -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 );
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/chuck_oo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, t_CKVEC4>::iterator iter = m_map.find( key );
Expand Down

0 comments on commit 51744ef

Please sign in to comment.