1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

net/nanocoap: return error from coap_opt_finish if no space

This commit is contained in:
Ken Bannister 2019-02-01 19:19:52 -05:00
parent 3cdf43607c
commit 5bf2fc6227
2 changed files with 4 additions and 1 deletions

View File

@ -669,6 +669,7 @@ static inline ssize_t coap_opt_add_format(coap_pkt_t *pkt, uint16_t format)
* @param[in] flags see COAP_OPT_FINISH... macros
*
* @return total number of bytes written to buffer
* @return -ENOSPC if no buffer space for payload marker
*/
ssize_t coap_opt_finish(coap_pkt_t *pkt, uint16_t flags);

View File

@ -797,7 +797,9 @@ ssize_t coap_opt_add_uint(coap_pkt_t *pkt, uint16_t optnum, uint32_t value)
ssize_t coap_opt_finish(coap_pkt_t *pkt, uint16_t flags)
{
if (flags & COAP_OPT_FINISH_PAYLOAD) {
assert(pkt->payload_len > 1);
if (!pkt->payload_len) {
return -ENOSPC;
}
*pkt->payload++ = 0xFF;
pkt->payload_len--;