diff --git a/src/core/common/encoding.hpp b/src/core/common/encoding.hpp index bf35678a0..786c8aa4f 100644 --- a/src/core/common/encoding.hpp +++ b/src/core/common/encoding.hpp @@ -76,7 +76,7 @@ inline uint32_t Reverse32(uint32_t v) return v; } -#define BitVectorBytes(x) (((x) + (CHAR_BIT - 1)) / CHAR_BIT) +#define BitVectorBytes(x) static_cast(((x) + (CHAR_BIT - 1)) / CHAR_BIT) namespace BigEndian { diff --git a/src/core/thread/network_data_tlvs.hpp b/src/core/thread/network_data_tlvs.hpp index 26de34ad2..4de23f10f 100644 --- a/src/core/thread/network_data_tlvs.hpp +++ b/src/core/thread/network_data_tlvs.hpp @@ -345,7 +345,8 @@ public: bool IsValid(void) const { return ((GetLength() >= sizeof(*this) - sizeof(NetworkDataTlv)) && - (GetLength() >= BitVectorBytes(mPrefixLength) + sizeof(*this) - sizeof(NetworkDataTlv))); + (GetLength() >= BitVectorBytes(mPrefixLength) + sizeof(*this) - sizeof(NetworkDataTlv)) && + (BitVectorBytes(mPrefixLength) <= sizeof(Ip6::Address))); } /**