Skip to content

Commit c3795f0

Browse files
committed
pybricks.tools: Fix crash when cross() args are wrong type.
Add type checking to fix a crash if the arguments to `cross()` are not `Matrix` objects.
1 parent 3b3c775 commit c3795f0

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pybricks/tools/pb_type_matrix.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,9 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pb_geometry_vector_obj, 2, 3, pb_geometry_ve
578578

579579
// pybricks.tools.cross
580580
static mp_obj_t pb_type_matrix_cross(mp_obj_t a_in, mp_obj_t b_in) {
581+
if (!mp_obj_is_type(a_in, &pb_type_Matrix) || !mp_obj_is_type(b_in, &pb_type_Matrix)) {
582+
mp_raise_TypeError(MP_ERROR_TEXT("arguments must be Matrix objects"));
583+
}
581584

582585
// Get a and b vectors
583586
pb_type_Matrix_obj_t *a = MP_OBJ_TO_PTR(a_in);

0 commit comments

Comments
 (0)