From f70ce9a7a6ab5345e8d5091c4695cd5ad3c30cab Mon Sep 17 00:00:00 2001 From: Micha Rosenbaum Date: Mon, 9 Dec 2019 14:39:33 +0100 Subject: [PATCH] Update the buf_size after the cbor array is closed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling cbor_encoder_get_buffer_size before, does not get the correct buffer size, as the array isn’t finished yet. Also the encoder doesn’t seem to get updated until the aaray container is closed. --- saul_coap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saul_coap.c b/saul_coap.c index 4e561f0..732730d 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -206,13 +206,13 @@ static ssize_t _saul_type_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, voi if (dim > 0) { cbor_err = export_phydat_to_cbor(&aryEncoder, res, dim); - buf_size = cbor_encoder_get_buffer_size(&encoder, cbor_buf); } dev = dev->next; } cbor_err = cbor_encoder_close_container(&encoder, &aryEncoder); + buf_size = cbor_encoder_get_buffer_size(&encoder, cbor_buf); if (cbor_err == CborNoError && buf_size > 0 && pdu->payload_len >= buf_size) { memcpy(pdu->payload, cbor_buf, buf_size);