More size_t usage

This commit is contained in:
Scott Shawcroft 2019-08-27 12:49:46 -07:00
parent d956b3b359
commit 966a48b23a
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
4 changed files with 10 additions and 9 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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) {

View File

@ -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) {