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
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3

View file

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