mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-10 10:50:40 +03:00
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:
1 parent
60f699d535
commit
c7e9359f02
21 files changed
+215
-129
No files matched your search
+7
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user