Make coap_encode_var_bytes() by replacing with coap_encode_var_safe()

Update code / examples / man pages with the updated function.

include/coap/libcoap.h:
Add in new define COAP_DEPRECATED to generate compiler warnings when used

include/coap/encode.h
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.

Make coap_encode_var_bytes() a wrapper for coap_encode_var_safe() and
mark it as COAP_DEPRECATED for backwards compatability

src/encode.c:
New coap_encode_var_safe() function that includes the size of the output
buffer as a parameter.

examples/coap-server.c:
examples/contiki/server.c:
Make the ticks resource consistent in case
This commit is contained in:
Jon Shallow committed 2018-06-05 09:41:58 +01:00
1 parent 60f699d535
commit c7e9359f02
21 files changed
+215 -129

No files matched your search

+7 -1
View File
@@ -11,6 +11,8 @@
#endif
#include "coap_config.h"
#include "coap.h"
#include "mem.h"
#include "encode.h"
/* Carsten suggested this when fls() is not available: */
@@ -40,12 +42,16 @@ coap_decode_var_bytes(const uint8_t *buf,unsigned int len) {
}
unsigned int
coap_encode_var_bytes(uint8_t *buf, unsigned int val) {
coap_encode_var_safe(uint8_t *buf, size_t length, unsigned int val) {
unsigned int n, i;
for (n = 0, i = val; i && n < sizeof(val); ++n)
i >>= 8;
if (n > length) {
assert (n <= length);
return 0;
}
i = n;
while (i--) {
buf[i] = val & 0xff;