More size_t usage

crypto-aes
Scott Shawcroft 3 years ago
parent d956b3b359
commit 966a48b23a
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
  1. 4
      lib/utils/buffer_helper.c
  2. 3
      lib/utils/buffer_helper.h
  3. 4
      shared-bindings/bitbangio/SPI.c
  4. 8
      shared-bindings/busio/SPI.c

@ -26,10 +26,10 @@
#include "lib/utils/buffer_helper.h"
void normalize_buffer_bounds(int32_t* start, int32_t end, uint32_t* length) {
void normalize_buffer_bounds(int32_t* start, int32_t end, size_t* length) {
if (end < 0) {
end += *length;
} else if (((uint32_t) end) > *length) {
} else if (((size_t) end) > *length) {
end = *length;
}
if (*start < 0) {

@ -28,7 +28,8 @@
#define MICROPY_INCLUDED_LIB_UTILS_BUFFER_HELPER_H
#include <stdint.h>
#include <string.h>
void normalize_buffer_bounds(int32_t* start, int32_t end, uint32_t* length);
void normalize_buffer_bounds(int32_t* start, int32_t end, size_t* length);
#endif // MICROPY_INCLUDED_LIB_UTILS_BUFFER_HELPER_H

@ -275,13 +275,13 @@ STATIC mp_obj_t bitbangio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_
mp_buffer_info_t buf_out_info;
mp_get_buffer_raise(args[ARG_buffer_out].u_obj, &buf_out_info, MP_BUFFER_READ);
int32_t out_start = args[ARG_out_start].u_int;
uint32_t out_length = buf_out_info.len;
size_t out_length = buf_out_info.len;
normalize_buffer_bounds(&out_start, args[ARG_out_end].u_int, &out_length);
mp_buffer_info_t buf_in_info;
mp_get_buffer_raise(args[ARG_buffer_in].u_obj, &buf_in_info, MP_BUFFER_WRITE);
int32_t in_start = args[ARG_in_start].u_int;
uint32_t in_length = buf_in_info.len;
size_t in_length = buf_in_info.len;
normalize_buffer_bounds(&in_start, args[ARG_in_end].u_int, &in_length);
if (out_length != in_length) {

@ -244,7 +244,7 @@ STATIC mp_obj_t busio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_map_
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ);
int32_t start = args[ARG_start].u_int;
uint32_t length = bufinfo.len;
size_t length = bufinfo.len;
normalize_buffer_bounds(&start, args[ARG_end].u_int, &length);
if (length == 0) {
@ -288,7 +288,7 @@ STATIC mp_obj_t busio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_m
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_WRITE);
int32_t start = args[ARG_start].u_int;
uint32_t length = bufinfo.len;
size_t length = bufinfo.len;
normalize_buffer_bounds(&start, args[ARG_end].u_int, &length);
if (length == 0) {
@ -337,13 +337,13 @@ STATIC mp_obj_t busio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args
mp_buffer_info_t buf_out_info;
mp_get_buffer_raise(args[ARG_buffer_out].u_obj, &buf_out_info, MP_BUFFER_READ);
int32_t out_start = args[ARG_out_start].u_int;
uint32_t out_length = buf_out_info.len;
size_t out_length = buf_out_info.len;
normalize_buffer_bounds(&out_start, args[ARG_out_end].u_int, &out_length);
mp_buffer_info_t buf_in_info;
mp_get_buffer_raise(args[ARG_buffer_in].u_obj, &buf_in_info, MP_BUFFER_WRITE);
int32_t in_start = args[ARG_in_start].u_int;
uint32_t in_length = buf_in_info.len;
size_t in_length = buf_in_info.len;
normalize_buffer_bounds(&in_start, args[ARG_in_end].u_int, &in_length);
if (out_length != in_length) {

Loading…
Cancel
Save