Skip to content

Commit 6ca4fd8

Browse files
committed
Add a type check to the gamepad module
Make sure that all the arguments passed are indeed DigitalInOut. This avoids crashes when the users pass something else.
1 parent 3215b85 commit 6ca4fd8

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

shared-bindings/gamepad/GamePad.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "py/runtime.h"
2828
#include "py/mphal.h"
2929
#include "shared-module/gamepad/GamePad.h"
30+
#include "shared-bindings/digitalio/DigitalInOut.h"
3031
#include "GamePad.h"
3132

3233

@@ -96,6 +97,12 @@ STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args,
9697
gamepad_singleton = m_new_obj(gamepad_obj_t);
9798
gamepad_singleton->base.type = &gamepad_type;
9899
}
100+
for (size_t i = 0; i < n_args; ++i) {
101+
if (!MP_OBJ_IS_TYPE(args[i], &digitalio_digitalinout_type)) {
102+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
103+
"Expected a %q", digitalio_digitalinout_type.name));
104+
}
105+
}
99106
gamepad_init(n_args, args);
100107
return MP_OBJ_FROM_PTR(gamepad_singleton);
101108
}

0 commit comments

Comments
 (0)