From c5b33851d73d3087ce7bdda2a3113a205d584b17 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 18 Sep 2016 14:13:38 +0300 Subject: [PATCH] zephyr/modsocket: socket_write: Send only data fitting in a netbuf. --- zephyr/modsocket.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zephyr/modsocket.c b/zephyr/modsocket.c index b286d7e6f..eb414fc0b 100644 --- a/zephyr/modsocket.c +++ b/zephyr/modsocket.c @@ -184,6 +184,9 @@ STATIC mp_uint_t socket_write(mp_obj_t self_in, const void *buf, mp_uint_t len, } struct net_buf *netbuf = ip_buf_get_tx(self->sock); + if (len > net_buf_tailroom(netbuf)) { + len = net_buf_tailroom(netbuf); + } uint8_t *ptr = net_buf_add(netbuf, len); memcpy(ptr, buf, len); ip_buf_appdatalen(netbuf) = len;