improved encoding of zero-length options

This commit is contained in:
Olaf Bergmann committed 2012-03-14 17:09:59 +01:00
1 parent de41dd7c44
commit c6473cacf4
1 file changed
+8 -6
+8 -6
View File
@@ -32,15 +32,17 @@ coap_decode_var_bytes(unsigned char *buf,unsigned int len) {
unsigned int
coap_encode_var_bytes(unsigned char *buf, unsigned int val) {
int n, i = val >> 1;
for (n = 0; i; n++) /* FIXME: coap_fls() */
i >>= 1;
unsigned int n, i;
for (i = n / 8 + 1; i; --i) {
buf[i-1] = val & 0xff;
for (n = 0, i = val; i && n < sizeof(val); ++n)
i >>= 8;
i = n;
while (i--) {
buf[i] = val & 0xff;
val >>= 8;
}
return n / 8 + 1;
return n;
}