Skip to content

Commit 8b32c1b

Browse files
committed
Correct handler range checks
1 parent 54adc3f commit 8b32c1b

9 files changed

+46
-32
lines changed

atom/src/defaultvaluebehavior.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,20 @@ handlers[] = {
202202
call_object_object_name_handler,
203203
object_method_handler,
204204
object_method_name_handler,
205-
member_method_object_handler
205+
member_method_object_handler,
206+
no_op_handler,
207+
no_op_handler
206208
};
207209

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

209212
} // namespace
210213

211214

212215
PyObject*
213216
Member::default_value( CAtom* atom )
214217
{
215-
if( get_default_value_mode() >= sizeof( handlers ) )
216-
return no_op_handler( this, atom ); // LCOV_EXCL_LINE
217-
return handlers[ get_default_value_mode() ]( this, atom );
218+
return handlers[ get_default_value_mode() & 0xf ]( this, atom );
218219
}
219220

220221

atom/src/delattrbehavior.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,15 @@ handlers[] = {
192192
property_handler
193193
};
194194

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

196197
} // namespace
197198

198199

199200
int
200201
Member::delattr( CAtom* atom )
201202
{
202-
if( get_delattr_mode() >= sizeof( handlers ) )
203-
return no_op_handler( this, atom ); // LCOV_EXCL_LINE
204-
return handlers[ get_delattr_mode() ]( this, atom );
203+
return handlers[ get_delattr_mode() & 0x7 ]( this, atom );
205204
}
206205

207206

atom/src/getattrbehavior.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,22 @@ handlers[] = {
256256
call_object_object_name_handler,
257257
object_method_handler,
258258
object_method_name_handler,
259-
member_method_object_handler
259+
member_method_object_handler,
260+
no_op_handler,
261+
no_op_handler,
262+
no_op_handler,
263+
no_op_handler
260264
};
261265

266+
static_assert( sizeof(handlers) / sizeof(handler) == 16, "Must be exactly 16 handlers" );
267+
262268
} // namespace
263269

264270

265271
PyObject*
266272
Member::getattr( CAtom* atom )
267273
{
268-
if( get_getattr_mode() >= sizeof( handlers ) )
269-
return no_op_handler( this, atom ); // LCOV_EXCL_LINE
270-
return handlers[ get_getattr_mode() ]( this, atom );
274+
return handlers[ get_getattr_mode() & 0xf ]( this, atom );
271275
}
272276

273277
} // namespace atom

atom/src/getstatebehavior.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,20 @@ handlers[] = {
124124
include_non_default_handler,
125125
property_handler,
126126
object_method_name_handler,
127-
member_method_object_handler
127+
member_method_object_handler,
128+
include_handler,
129+
include_handler
128130
};
129131

132+
static_assert( sizeof(handlers) / sizeof(handler) == 8, "Must be exactly 8 handlers" );
133+
130134
} // namespace
131135

132136

133137
PyObject*
134138
Member::should_getstate( CAtom* atom )
135139
{
136-
if( get_getstate_mode() >= sizeof( handlers ) )
137-
return include_handler( this, atom ); // LCOV_EXCL_LINE
138-
return handlers[ get_getstate_mode() ]( this, atom );
140+
return handlers[ get_getstate_mode() & 0x7 ]( this, atom );
139141
}
140142

141143
} // namespace atom

atom/src/postgetattrbehavior.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,21 @@ handlers[] = {
9393
delegate_handler,
9494
object_method_value_handler,
9595
object_method_name_value_handler,
96-
member_method_object_value_handler
96+
member_method_object_value_handler,
97+
no_op_handler,
98+
no_op_handler,
99+
no_op_handler,
97100
};
98101

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

100104
} // namespace
101105

102106

103107
PyObject*
104108
Member::post_getattr( CAtom* atom, PyObject* value )
105109
{
106-
if( get_post_getattr_mode() >= sizeof( handlers ) )
107-
return no_op_handler( this, atom, value ); // LCOV_EXCL_LINE
108-
return handlers[ get_post_getattr_mode() ]( this, atom, value );
110+
return handlers[ get_post_getattr_mode() & 0x7 ]( this, atom, value );
109111
}
110112

111113

atom/src/postsetattrbehavior.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,21 @@ handlers[] = {
106106
delegate_handler,
107107
object_method_old_new_handler,
108108
object_method_name_old_new_handler,
109-
member_method_object_old_new_handler
109+
member_method_object_old_new_handler,
110+
no_op_handler,
111+
no_op_handler,
112+
no_op_handler
110113
};
111114

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

113117
} // namespace
114118

115119

116120
int
117121
Member::post_setattr( CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
118122
{
119-
if( get_post_setattr_mode() >= sizeof( handlers ) )
120-
return no_op_handler( this, atom, oldvalue, newvalue ); // LCOV_EXCL_LINE
121-
return handlers[ get_post_setattr_mode() ]( this, atom, oldvalue, newvalue );
123+
return handlers[ get_post_setattr_mode() & 0x7 ]( this, atom, oldvalue, newvalue );
122124
}
123125

124126

atom/src/postvalidatebehavior.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,21 @@ handlers[] = {
9797
delegate_handler,
9898
object_method_old_new_handler,
9999
object_method_name_old_new_handler,
100-
member_method_object_old_new_handler
100+
member_method_object_old_new_handler,
101+
no_op_handler,
102+
no_op_handler,
103+
no_op_handler
101104
};
102105

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

104108
} // namespace
105109

106110

107111
PyObject*
108112
Member::post_validate( CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
109113
{
110-
if( get_post_validate_mode() >= sizeof( handlers ) )
111-
return no_op_handler( this, atom, oldvalue, newvalue ); // LCOV_EXCL_LINE
112-
return handlers[ get_post_validate_mode() ]( this, atom, oldvalue, newvalue );
114+
return handlers[ get_post_validate_mode() & 0x7 ]( this, atom, oldvalue, newvalue );
113115
}
114116

115117
} // namespace atom

atom/src/setattrbehavior.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -377,19 +377,21 @@ handlers[] = {
377377
call_object_object_name_value_handler,
378378
object_method_value_handler,
379379
object_method_name_value_handler,
380-
member_method_object_value_handler
380+
member_method_object_value_handler,
381+
no_op_handler,
382+
no_op_handler,
383+
no_op_handler
381384
};
382385

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

384388
} // namespace
385389

386390

387391
int
388392
Member::setattr( CAtom* atom, PyObject* value )
389393
{
390-
if( get_setattr_mode() >= sizeof( handlers ) )
391-
return no_op_handler( this, atom, value ); // LCOV_EXCL_LINE
392-
return handlers[ get_setattr_mode() ]( this, atom, value );
394+
return handlers[ get_setattr_mode() & 0xf ]( this, atom, value );
393395
}
394396

395397

atom/src/validatebehavior.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ handlers[] = {
10071007
PyObject*
10081008
Member::validate( CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
10091009
{
1010-
if( get_validate_mode() >= sizeof( handlers ) )
1010+
if( get_validate_mode() >= sizeof( handlers ) / sizeof( handler ) )
10111011
return no_op_handler( this, atom, oldvalue, newvalue ); // LCOV_EXCL_LINE
10121012
return handlers[ get_validate_mode() ]( this, atom, oldvalue, newvalue );
10131013
}

0 commit comments

Comments
 (0)