Skip to content

Commit

Permalink
Update the buf_size after the cbor array is closed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rosetree committed Dec 9, 2019
1 parent 06e7c1a commit f70ce9a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion saul_coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f70ce9a

Please sign in to comment.