format_tlv_len() accepts NULL argument.

In that case, it returns the length of the length in bytes.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2022-05-24 14:27:49 +02:00
parent 5e2fc081f1
commit 5a30c7cbdc

View File

@@ -1495,18 +1495,23 @@ void led_off_all() {
int format_tlv_len(size_t len, uint8_t *out) { int format_tlv_len(size_t len, uint8_t *out) {
if (len < 128) { if (len < 128) {
*out = len; if (out)
*out = len;
return 1; return 1;
} }
else if (len < 256) { else if (len < 256) {
*out++ = 0x81; if (out) {
*out++ = len; *out++ = 0x81;
*out++ = len;
}
return 2; return 2;
} }
else { else {
*out++ = 0x82; if (out) {
*out++ = (len >> 8) & 0xff; *out++ = 0x82;
*out++ = len & 0xff; *out++ = (len >> 8) & 0xff;
*out++ = len & 0xff;
}
return 3; return 3;
} }
return 0; return 0;