Fix SPI readinto with negative start or end

This commit is contained in:
Scott Shawcroft 2023-01-12 16:25:11 -08:00
parent 987d9a31c8
commit 8b0db804ba
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
1 changed files with 1 additions and 1 deletions

View File

@ -333,7 +333,7 @@ STATIC mp_obj_t busio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_m
// Compute bounds in terms of elements, not bytes. // Compute bounds in terms of elements, not bytes.
int stride_in_bytes = mp_binary_get_size('@', bufinfo.typecode, NULL); int stride_in_bytes = mp_binary_get_size('@', bufinfo.typecode, NULL);
int32_t start = args[ARG_start].u_int; int32_t start = args[ARG_start].u_int;
size_t length = bufinfo.len; size_t length = bufinfo.len / stride_in_bytes;
normalize_buffer_bounds(&start, args[ARG_end].u_int, &length); normalize_buffer_bounds(&start, args[ARG_end].u_int, &length);
// Treat start and length in terms of bytes from now on. // Treat start and length in terms of bytes from now on.