Skip to content

Commit 888d710

Browse files
committed
Correct handler range checks
1 parent c365c61 commit 888d710

10 files changed

+88
-42
lines changed

atom/src/behaviors.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace atom
1414
namespace GetAttr
1515
{
1616

17-
enum Mode
17+
enum Mode: uint8_t
1818
{
1919
NoOp,
2020
Slot,
@@ -37,7 +37,7 @@ enum Mode
3737
namespace PostGetAttr
3838
{
3939

40-
enum Mode
40+
enum Mode: uint8_t
4141
{
4242
NoOp,
4343
Delegate,
@@ -53,7 +53,7 @@ enum Mode
5353
namespace SetAttr
5454
{
5555

56-
enum Mode
56+
enum Mode: uint8_t
5757
{
5858
NoOp,
5959
Slot,
@@ -77,7 +77,7 @@ enum Mode
7777
namespace PostSetAttr
7878
{
7979

80-
enum Mode
80+
enum Mode: uint8_t
8181
{
8282
NoOp,
8383
Delegate,
@@ -94,7 +94,7 @@ enum Mode
9494
namespace DefaultValue
9595
{
9696

97-
enum Mode
97+
enum Mode: uint8_t
9898
{
9999
NoOp,
100100
Static,
@@ -119,7 +119,7 @@ enum Mode
119119
namespace Validate
120120
{
121121

122-
enum Mode
122+
enum Mode: uint8_t
123123
{
124124
NoOp,
125125
Bool,
@@ -162,7 +162,7 @@ enum Mode
162162
namespace PostValidate
163163
{
164164

165-
enum Mode
165+
enum Mode: uint8_t
166166
{
167167
NoOp,
168168
Delegate,
@@ -178,7 +178,7 @@ enum Mode
178178
namespace DelAttr
179179
{
180180

181-
enum Mode
181+
enum Mode: uint8_t
182182
{
183183
NoOp,
184184
Slot,
@@ -197,7 +197,7 @@ enum Mode
197197
namespace GetState
198198
{
199199

200-
enum Mode
200+
enum Mode: uint8_t
201201
{
202202
Include, // We want include to be the default behavior
203203
Exclude,

atom/src/defaultvaluebehavior.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,19 @@ 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
206207
};
207208

209+
static_assert( sizeof(handlers) / sizeof(handler) == 0xF, "Must be exactly 15 handlers" );
208210

209211
} // namespace
210212

211213

212214
PyObject*
213215
Member::default_value( CAtom* atom )
214216
{
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 );
217+
return handlers[ get_default_value_mode() & 0xF ]( this, atom );
218218
}
219219

220220

atom/src/delattrbehavior.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,25 @@ handlers[] = {
189189
event_handler,
190190
signal_handler,
191191
delegate_handler,
192-
property_handler
192+
property_handler,
193+
no_op_handler,
194+
no_op_handler,
195+
no_op_handler,
196+
no_op_handler,
197+
no_op_handler,
198+
no_op_handler,
199+
no_op_handler
193200
};
194201

202+
static_assert( sizeof(handlers) / sizeof(handler) == 0xf, "Must be exactly 15 handlers" );
195203

196204
} // namespace
197205

198206

199207
int
200208
Member::delattr( CAtom* atom )
201209
{
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 );
210+
return handlers[ get_delattr_mode() & 0xf ]( this, atom );
205211
}
206212

207213

atom/src/getattrbehavior.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,21 @@ 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
260263
};
261264

265+
static_assert( sizeof(handlers) / sizeof(handler) == 0xf, "Must be exactly 15 handlers" );
266+
262267
} // namespace
263268

264269

265270
PyObject*
266271
Member::getattr( CAtom* atom )
267272
{
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 );
273+
return handlers[ get_getattr_mode() & 0xf ]( this, atom );
271274
}
272275

273276
} // namespace atom

atom/src/getstatebehavior.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,27 @@ 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,
130+
include_handler,
131+
include_handler,
132+
include_handler,
133+
include_handler,
134+
include_handler,
135+
include_handler,
136+
include_handler
128137
};
129138

139+
static_assert( sizeof(handlers) / sizeof(handler) == 0xf, "Must be exactly 15 handlers" );
140+
130141
} // namespace
131142

132143

133144
PyObject*
134145
Member::should_getstate( CAtom* atom )
135146
{
136-
if( get_getstate_mode() >= sizeof( handlers ) )
137-
return include_handler( this, atom ); // LCOV_EXCL_LINE
138-
return handlers[ get_getstate_mode() ]( this, atom );
147+
return handlers[ get_getstate_mode() & 0xf ]( this, atom );
139148
}
140149

141150
} // namespace atom

atom/src/postgetattrbehavior.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,28 @@ 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,
100+
no_op_handler,
101+
no_op_handler,
102+
no_op_handler,
103+
no_op_handler,
104+
no_op_handler,
105+
no_op_handler,
106+
no_op_handler
97107
};
98108

109+
static_assert( sizeof(handlers) / sizeof(handler) == 0xf, "Must be exactly 15 handlers" );
99110

100111
} // namespace
101112

102113

103114
PyObject*
104115
Member::post_getattr( CAtom* atom, PyObject* value )
105116
{
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 );
117+
return handlers[ get_post_getattr_mode() & 0xf ]( this, atom, value );
109118
}
110119

111120

atom/src/postsetattrbehavior.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,28 @@ 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,
113+
no_op_handler,
114+
no_op_handler,
115+
no_op_handler,
116+
no_op_handler,
117+
no_op_handler,
118+
no_op_handler,
119+
no_op_handler
110120
};
111121

122+
static_assert( sizeof(handlers) / sizeof(handler) == 0xf, "Must be exactly 15 handlers" );
112123

113124
} // namespace
114125

115126

116127
int
117128
Member::post_setattr( CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
118129
{
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 );
130+
return handlers[ get_post_setattr_mode() & 0xf ]( this, atom, oldvalue, newvalue );
122131
}
123132

124133

atom/src/postvalidatebehavior.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,28 @@ 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,
104+
no_op_handler,
105+
no_op_handler,
106+
no_op_handler,
107+
no_op_handler,
108+
no_op_handler,
109+
no_op_handler,
110+
no_op_handler
101111
};
102112

113+
static_assert( sizeof(handlers) / sizeof(handler) == 0xf, "Must be exactly 15 handlers" );
103114

104115
} // namespace
105116

106117

107118
PyObject*
108119
Member::post_validate( CAtom* atom, PyObject* oldvalue, PyObject* newvalue )
109120
{
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 );
121+
return handlers[ get_post_validate_mode() & 0xf ]( this, atom, oldvalue, newvalue );
113122
}
114123

115124
} // namespace atom

atom/src/setattrbehavior.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,19 +377,20 @@ 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
381383
};
382384

385+
static_assert( sizeof(handlers) / sizeof(handler) == 0xf, "Must be exactly 15 handlers" );
383386

384387
} // namespace
385388

386389

387390
int
388391
Member::setattr( CAtom* atom, PyObject* value )
389392
{
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 );
393+
return handlers[ get_setattr_mode() & 0xf ]( this, atom, value );
393394
}
394395

395396

atom/src/validatebehavior.cpp

Lines changed: 1 addition & 1 deletion
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)