Undefined behaviour fixes

Fixes issues reported in #8120
This commit is contained in:
SChernykh 2022-02-19 10:17:53 +01:00
parent 9aab19f349
commit f68f92776b
6 changed files with 24 additions and 12 deletions

View file

@ -157,6 +157,18 @@ namespace epee
pod_val = CONVERT_POD(pod_val);
}
template<>
void throwable_buffer_reader::read<bool>(bool& pod_val)
{
RECURSION_LIMITATION();
static_assert(std::is_pod<bool>::value, "POD type expected");
static_assert(sizeof(bool) == sizeof(uint8_t), "We really shouldn't use bool directly in serialization code. Replace it with uint8_t if this assert triggers!");
uint8_t t;
read(&t, sizeof(t));
CHECK_AND_ASSERT_THROW_MES(t <= 1, "Invalid bool value " << t);
pod_val = (t != 0);
}
template<class t_type>
t_type throwable_buffer_reader::read()
{