UI: Net/Ip4Range: Fix PVS-Studio warning.

V610 Undefined behavior. Check the shift operator '<<'. The right operand ('(32 - nbits)' = [1..32]) is greater than or equal to the length in bits of the promoted left operand. ip4range.cpp 152
This commit is contained in:
Nodir Temirkhodjaev 2021-06-19 17:54:07 +03:00
parent cf2ed5ad8f
commit a05ee35f68
2 changed files with 4 additions and 1 deletions

View File

@ -41,6 +41,9 @@ TEST_F(NetUtilTest, ip4Ranges)
ASSERT_TRUE(ip4Range.fromText("172.16.0.1/32"));
ASSERT_EQ(ip4Range.toText(), QString("172.16.0.1\n"));
ASSERT_TRUE(ip4Range.fromText("172.16.0.1/0"));
ASSERT_EQ(ip4Range.toText(), QString("172.16.0.1-255.255.255.255\n"));
// Simple range
{
ASSERT_TRUE(ip4Range.fromText("127.0.0.1\n"

View File

@ -149,7 +149,7 @@ bool Ip4Range::parseAddressMask(const StringView line, quint32 &from, quint32 &t
return false;
}
to = from | (nbits == 32 ? 0 : ((1 << (32 - nbits)) - 1));
to = nbits == 0 ? quint32(-1) : (from | (nbits == 32 ? 0 : ((1 << (32 - nbits)) - 1)));
}
return true;