From 7d5a22d6b91bcb94ed059b349712163238f55d42 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Mon, 2 Feb 2015 17:14:09 +0100 Subject: [PATCH] Fix types of coap_option_nibble() Input values for coap_option_nibble() can be > 0xffff; i. e. type must be uint32_t. --- coap.c | 7 ++++--- coap.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/coap.c b/coap.c index 10f6cb8..07b8351 100644 --- a/coap.c +++ b/coap.c @@ -294,13 +294,14 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt) for (i=0;inumopts;i++) { - uint8_t optDelta, len, delta = 0; + uint32_t optDelta; + uint8_t len, delta = 0; if (p-buf > *buflen) return COAP_ERR_BUFFER_TOO_SMALL; optDelta = pkt->opts[i].num - running_delta; coap_option_nibble(optDelta, &delta); - coap_option_nibble(pkt->opts[i].buf.len, &len); + coap_option_nibble((uint32_t)pkt->opts[i].buf.len, &len); *p++ = (0xFF & (delta << 4 | len)); if (delta == 13) @@ -344,7 +345,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt) return 0; } -void coap_option_nibble(uint8_t value, uint8_t *nibble) +void coap_option_nibble(uint32_t value, uint8_t *nibble) { if (value<13) { diff --git a/coap.h b/coap.h index 4205f3b..c132334 100644 --- a/coap.h +++ b/coap.h @@ -153,7 +153,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt); void coap_dump(const uint8_t *buf, size_t buflen, bool bare); int coap_make_response(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const uint8_t *content, size_t content_len, uint8_t msgid_hi, uint8_t msgid_lo, const coap_buffer_t* tok, coap_responsecode_t rspcode, coap_content_type_t content_type); int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt); -void coap_option_nibble(uint8_t value, uint8_t *nibble); +void coap_option_nibble(uint32_t value, uint8_t *nibble); void coap_setup(void); void endpoint_setup(void);