mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
* bug fix: Packet::writeTo(), Packet::readFrom()
This commit is contained in:
parent
ca81f645ed
commit
b67decfba0
1 changed files with 6 additions and 3 deletions
|
|
@ -57,7 +57,7 @@ uint8_t Packet::writeTo(uint8_t dest[]) const {
|
||||||
memcpy(&dest[i], &transport_codes[1], 2); i += 2;
|
memcpy(&dest[i], &transport_codes[1], 2); i += 2;
|
||||||
}
|
}
|
||||||
dest[i++] = path_len;
|
dest[i++] = path_len;
|
||||||
memcpy(&dest[i], path, path_len); i += path_len;
|
i += writePath(&dest[i], path, path_len);
|
||||||
memcpy(&dest[i], payload, payload_len); i += payload_len;
|
memcpy(&dest[i], payload, payload_len); i += payload_len;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
@ -72,8 +72,11 @@ bool Packet::readFrom(const uint8_t src[], uint8_t len) {
|
||||||
transport_codes[0] = transport_codes[1] = 0;
|
transport_codes[0] = transport_codes[1] = 0;
|
||||||
}
|
}
|
||||||
path_len = src[i++];
|
path_len = src[i++];
|
||||||
if (path_len > sizeof(path)) return false; // bad encoding
|
if (!isValidPathLen(path_len)) return false; // bad encoding
|
||||||
memcpy(path, &src[i], path_len); i += path_len;
|
|
||||||
|
uint8_t bl = getPathByteLen();
|
||||||
|
memcpy(path, &src[i], bl); i += bl;
|
||||||
|
|
||||||
if (i >= len) return false; // bad encoding
|
if (i >= len) return false; // bad encoding
|
||||||
payload_len = len - i;
|
payload_len = len - i;
|
||||||
if (payload_len > sizeof(payload)) return false; // bad encoding
|
if (payload_len > sizeof(payload)) return false; // bad encoding
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue