Skip to content

Commit

Permalink
codal_port/microbit_spi: Raise ValueError if spi.read arg is negative.
Browse files Browse the repository at this point in the history
Fixes issue #208.

Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed May 20, 2024
1 parent 15b467c commit ef2a57e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/codal_port/microbit_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ MP_DEFINE_CONST_FUN_OBJ_2(microbit_spi_write_obj, microbit_spi_write);

STATIC mp_obj_t microbit_spi_read(size_t n_args, const mp_obj_t *args) {
microbit_spi_check_initialised();
mp_int_t nbytes = mp_obj_get_int(args[1]);
if (nbytes < 0) {
mp_raise_ValueError(MP_ERROR_TEXT("invalid number of bytes"));
}
vstr_t vstr;
vstr_init_len(&vstr, mp_obj_get_int(args[1]));
vstr_init_len(&vstr, nbytes);
uint8_t byte_out = 0;
if (n_args == 3) {
byte_out = mp_obj_get_int(args[2]);
Expand Down

0 comments on commit ef2a57e

Please sign in to comment.