diff options
author | SChernykh <sergey.v.chernykh@gmail.com> | 2022-02-19 10:17:53 +0100 |
---|---|---|
committer | SChernykh <sergey.v.chernykh@gmail.com> | 2022-02-19 10:17:53 +0100 |
commit | f68f92776baf89b65db41314102663be533cdb1a (patch) | |
tree | 0ac380e4d1f427701bf8db61eb1fe77115d0c773 /contrib/epee/include/storages | |
parent | Merge pull request #8135 (diff) | |
download | monero-f68f92776baf89b65db41314102663be533cdb1a.tar.xz |
Undefined behaviour fixes
Fixes issues reported in #8120
Diffstat (limited to 'contrib/epee/include/storages')
-rw-r--r-- | contrib/epee/include/storages/portable_storage_from_bin.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/contrib/epee/include/storages/portable_storage_from_bin.h b/contrib/epee/include/storages/portable_storage_from_bin.h index 9e7b6ec34..6f081dbc7 100644 --- a/contrib/epee/include/storages/portable_storage_from_bin.h +++ b/contrib/epee/include/storages/portable_storage_from_bin.h @@ -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() { |