summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-03-25 17:41:47 -0700
committerScott Shawcroft <scott@tannewt.org>2020-03-25 17:41:47 -0700
commit8a5d3cd6c4a5c68606aafa7373a7b5fc2079a936 (patch)
treec2ff20916a87e29f5913f81bbc46d621a9c2171a /shared-bindings
parent3551b769a27c442780e978ea7a58cc56170cdfc8 (diff)
Add exception on small buffer and fix Connecion WRITE handling
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/_bleio/PacketBuffer.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/shared-bindings/_bleio/PacketBuffer.c b/shared-bindings/_bleio/PacketBuffer.c
index 3ed295f01..9e3666044 100644
--- a/shared-bindings/_bleio/PacketBuffer.c
+++ b/shared-bindings/_bleio/PacketBuffer.c
@@ -109,7 +109,12 @@ STATIC mp_obj_t bleio_packet_buffer_readinto(mp_obj_t self_in, mp_obj_t buffer_o
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buffer_obj, &bufinfo, MP_BUFFER_WRITE);
- return MP_OBJ_NEW_SMALL_INT(common_hal_bleio_packet_buffer_readinto(self, bufinfo.buf, bufinfo.len));
+ int size = common_hal_bleio_packet_buffer_readinto(self, bufinfo.buf, bufinfo.len);
+ if (size < 0) {
+ mp_raise_ValueError_varg(translate("Buffer too short by %d bytes"), size * -1);
+ }
+
+ return MP_OBJ_NEW_SMALL_INT(size);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_packet_buffer_readinto_obj, bleio_packet_buffer_readinto);