Skip to content

Commit

Permalink
Correct handler range checks
Browse files Browse the repository at this point in the history
  • Loading branch information
frmdstryr committed Jan 21, 2025
1 parent 54adc3f commit 02a7da9
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 33 deletions.
9 changes: 5 additions & 4 deletions atom/src/defaultvaluebehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,20 @@ handlers[] = {
call_object_object_name_handler,
object_method_handler,
object_method_name_handler,
member_method_object_handler
member_method_object_handler,
no_op_handler,
no_op_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == 16, "Must be exactly 16 handlers" );

} // namespace


PyObject*
Member::default_value( CAtom* atom )
{
if( get_default_value_mode() >= sizeof( handlers ) )
return no_op_handler( this, atom ); // LCOV_EXCL_LINE
return handlers[ get_default_value_mode() ]( this, atom );
return handlers[ get_default_value_mode() & 0xf ]( this, atom );
}


Expand Down
7 changes: 3 additions & 4 deletions atom/src/delattrbehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,18 @@ handlers[] = {
event_handler,
signal_handler,
delegate_handler,
property_handler
property_handler,
};

static_assert( sizeof(handlers) / sizeof(handler) == 8, "Must be exactly 8 handlers" );

} // namespace


int
Member::delattr( CAtom* atom )
{
if( get_delattr_mode() >= sizeof( handlers ) )
return no_op_handler( this, atom ); // LCOV_EXCL_LINE
return handlers[ get_delattr_mode() ]( this, atom );
return handlers[ get_delattr_mode() & 0x7 ]( this, atom );
}


Expand Down
12 changes: 8 additions & 4 deletions atom/src/getattrbehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,22 @@ handlers[] = {
call_object_object_name_handler,
object_method_handler,
object_method_name_handler,
member_method_object_handler
member_method_object_handler,
no_op_handler,
no_op_handler,
no_op_handler,
no_op_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == 16, "Must be exactly 16 handlers" );

} // namespace


PyObject*
Member::getattr( CAtom* atom )
{
if( get_getattr_mode() >= sizeof( handlers ) )
return no_op_handler( this, atom ); // LCOV_EXCL_LINE
return handlers[ get_getattr_mode() ]( this, atom );
return handlers[ get_getattr_mode() & 0xf ]( this, atom );
}

} // namespace atom
10 changes: 6 additions & 4 deletions atom/src/getstatebehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,20 @@ handlers[] = {
include_non_default_handler,
property_handler,
object_method_name_handler,
member_method_object_handler
member_method_object_handler,
include_handler,
include_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == 8, "Must be exactly 8 handlers" );

} // namespace


PyObject*
Member::should_getstate( CAtom* atom )
{
if( get_getstate_mode() >= sizeof( handlers ) )
return include_handler( this, atom ); // LCOV_EXCL_LINE
return handlers[ get_getstate_mode() ]( this, atom );
return handlers[ get_getstate_mode() & 0x7 ]( this, atom );
}

} // namespace atom
10 changes: 6 additions & 4 deletions atom/src/postgetattrbehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,21 @@ handlers[] = {
delegate_handler,
object_method_value_handler,
object_method_name_value_handler,
member_method_object_value_handler
member_method_object_value_handler,
no_op_handler,
no_op_handler,
no_op_handler,
};

static_assert( sizeof(handlers) / sizeof(handler) == 8, "Must be exactly 8 handlers" );

} // namespace


PyObject*
Member::post_getattr( CAtom* atom, PyObject* value )
{
if( get_post_getattr_mode() >= sizeof( handlers ) )
return no_op_handler( this, atom, value ); // LCOV_EXCL_LINE
return handlers[ get_post_getattr_mode() ]( this, atom, value );
return handlers[ get_post_getattr_mode() & 0x7 ]( this, atom, value );
}


Expand Down
10 changes: 6 additions & 4 deletions atom/src/postsetattrbehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,21 @@ handlers[] = {
delegate_handler,
object_method_old_new_handler,
object_method_name_old_new_handler,
member_method_object_old_new_handler
member_method_object_old_new_handler,
no_op_handler,
no_op_handler,
no_op_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == 8, "Must be exactly 8 handlers" );

} // namespace


int
Member::post_setattr( CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
{
if( get_post_setattr_mode() >= sizeof( handlers ) )
return no_op_handler( this, atom, oldvalue, newvalue ); // LCOV_EXCL_LINE
return handlers[ get_post_setattr_mode() ]( this, atom, oldvalue, newvalue );
return handlers[ get_post_setattr_mode() & 0x7 ]( this, atom, oldvalue, newvalue );
}


Expand Down
10 changes: 6 additions & 4 deletions atom/src/postvalidatebehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,21 @@ handlers[] = {
delegate_handler,
object_method_old_new_handler,
object_method_name_old_new_handler,
member_method_object_old_new_handler
member_method_object_old_new_handler,
no_op_handler,
no_op_handler,
no_op_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == 8, "Must be exactly 8 handlers" );

} // namespace


PyObject*
Member::post_validate( CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
{
if( get_post_validate_mode() >= sizeof( handlers ) )
return no_op_handler( this, atom, oldvalue, newvalue ); // LCOV_EXCL_LINE
return handlers[ get_post_validate_mode() ]( this, atom, oldvalue, newvalue );
return handlers[ get_post_validate_mode() & 0x7 ]( this, atom, oldvalue, newvalue );
}

} // namespace atom
10 changes: 6 additions & 4 deletions atom/src/setattrbehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,19 +377,21 @@ handlers[] = {
call_object_object_name_value_handler,
object_method_value_handler,
object_method_name_value_handler,
member_method_object_value_handler
member_method_object_value_handler,
no_op_handler,
no_op_handler,
no_op_handler
};

static_assert( sizeof(handlers) / sizeof(handler) == 16, "Must be exactly 16 handlers" );

} // namespace


int
Member::setattr( CAtom* atom, PyObject* value )
{
if( get_setattr_mode() >= sizeof( handlers ) )
return no_op_handler( this, atom, value ); // LCOV_EXCL_LINE
return handlers[ get_setattr_mode() ]( this, atom, value );
return handlers[ get_setattr_mode() & 0xf ]( this, atom, value );
}


Expand Down
2 changes: 1 addition & 1 deletion atom/src/validatebehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ handlers[] = {
PyObject*
Member::validate( CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
{
if( get_validate_mode() >= sizeof( handlers ) )
if( get_validate_mode() >= sizeof( handlers ) / sizeof( handler ) )
return no_op_handler( this, atom, oldvalue, newvalue ); // LCOV_EXCL_LINE
return handlers[ get_validate_mode() ]( this, atom, oldvalue, newvalue );
}
Expand Down

0 comments on commit 02a7da9

Please sign in to comment.