diff --git a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx index 35784a16..9762d98d 100644 --- a/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx +++ b/ext/libnfb_ext_python/libnfb_ext_python/libnfb_ext_python.pyx @@ -53,13 +53,18 @@ cdef ssize_t nfb_pynfb_bus_read(void *p, void *buf, size_t nbyte, off_t offset) cdef PyObject* _bus = p cdef object bus = _bus cdef bytes data + cdef ssize_t ret nfb, comp_node, bus_node = bus data = nfb.read(bus_node, comp_node, offset, nbyte) - assert len(data) == int(nbyte) - memcpy(buf, data, nbyte) + ret = len(data) + if ret > int(nbyte): + ret = -1 - return nbyte + if ret > 0: + memcpy(buf, data, ret) + + return ret cdef ssize_t nfb_pynfb_bus_write(void *p, const void *buf, size_t nbyte, off_t offset) noexcept: cdef PyObject* _bus = p