1414
1515
1616// Converts a list of points tuples to a flat list of ints for speedier internal use.
17- // Also validates the points.
17+ // Also validates the points. If this fails due to invalid types or values, the
18+ // content of the points is undefined.
1819static void _clobber_points_list (vectorio_polygon_t * self , mp_obj_t points_tuple_list ) {
1920 size_t len = 0 ;
2021 mp_obj_t * items ;
@@ -26,12 +27,8 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
2627 }
2728
2829 if (self -> len < 2 * len ) {
29- if (self -> points_list != NULL ) {
30- VECTORIO_POLYGON_DEBUG ("free(%d), " , sizeof (self -> points_list ));
31- gc_free (self -> points_list );
32- }
33- self -> points_list = gc_alloc (2 * len * sizeof (uint16_t ), false, false);
34- VECTORIO_POLYGON_DEBUG ("alloc(%p, %d)" , self -> points_list , 2 * len * sizeof (uint16_t ));
30+ self -> points_list = gc_realloc (self -> points_list , 2 * len * sizeof (uint16_t ), true);
31+ VECTORIO_POLYGON_DEBUG ("realloc(%d) -> %p" , self -> points_list , 2 * len * sizeof (uint16_t ));
3532 }
3633 self -> len = 2 * len ;
3734
@@ -42,17 +39,10 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
4239
4340 mp_arg_validate_length (tuple_len , 2 , MP_QSTR_point );
4441
45- mp_int_t x ;
46- mp_int_t y ;
47- if (!mp_obj_get_int_maybe (tuple_items [ 0 ], & x )
48- || !mp_obj_get_int_maybe (tuple_items [ 1 ], & y )
49- || x < SHRT_MIN || x > SHRT_MAX || y < SHRT_MIN || y > SHRT_MAX
50- ) {
51- gc_free (self -> points_list );
52- self -> points_list = NULL ;
53- mp_raise_ValueError_varg (translate ("unsupported %q type" ), MP_QSTR_point );
54- self -> len = 0 ;
55- }
42+ mp_int_t x = mp_arg_validate_type_int (tuple_items [0 ], MP_QSTR_x );
43+ mp_arg_validate_int_range (x , SHRT_MIN , SHRT_MAX , MP_QSTR_x );
44+ mp_int_t y = mp_arg_validate_type_int (tuple_items [1 ], MP_QSTR_y );
45+ mp_arg_validate_int_range (y , SHRT_MIN , SHRT_MAX , MP_QSTR_y );
5646 self -> points_list [2 * i ] = (int16_t )x ;
5747 self -> points_list [2 * i + 1 ] = (int16_t )y ;
5848 }
0 commit comments