mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-21 01:01:41 +00:00
Add check for packet of incorrect length (#629)
Co-authored-by: Matt <matthew.morley.ca@gmail.com>
This commit is contained in:
@@ -99,13 +99,15 @@ class Packet {
|
||||
*/
|
||||
template <typename T>
|
||||
Packet& operator>>(T& value) {
|
||||
std::memcpy(&value, packetData.data() + readPos, sizeof(T));
|
||||
if (!packetData.empty()) {
|
||||
std::memcpy(&value, packetData.data() + readPos, sizeof(T));
|
||||
|
||||
if constexpr (wpi::support::endian::system_endianness() ==
|
||||
wpi::support::endianness::little) {
|
||||
// Reverse to little endian for host.
|
||||
char& raw = reinterpret_cast<char&>(value);
|
||||
std::reverse(&raw, &raw + sizeof(T));
|
||||
if constexpr (wpi::support::endian::system_endianness() ==
|
||||
wpi::support::endianness::little) {
|
||||
// Reverse to little endian for host.
|
||||
char& raw = reinterpret_cast<char&>(value);
|
||||
std::reverse(&raw, &raw + sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
readPos += sizeof(T);
|
||||
|
||||
Reference in New Issue
Block a user