[Bug 1868] Optimized builds are sensitive to -fstrict-overflow

This commit is contained in:
Peter D. Barnes, Jr.
2014-03-02 00:42:05 -08:00
parent 94a4233910
commit 3c032987f0
6 changed files with 19 additions and 8 deletions

View File

@@ -1313,7 +1313,8 @@ uint8_t DsrOptionSR::Process (Ptr<Packet> packet, Ptr<Packet> dsrP, Ipv4Address
m_dropTrace (packet);
return 0;
}
if (numberAddress - segsLeft - 2 < 0) // The index is invalid
// -fstrict-overflow sensitive, see bug 1868
if (numberAddress - segsLeft < 2) // The index is invalid
{
NS_LOG_LOGIC ("Malformed header. Drop!");
m_dropTrace (packet);

View File

@@ -1910,10 +1910,11 @@ uint32_t Icmpv6OptionLinkLayerAddress::Deserialize (Buffer::Iterator start)
SetType (i.ReadU8 ());
SetLength (i.ReadU8 ());
NS_ASSERT (GetLength () * 8 - 2 <= 32);
// -fstrict-overflow sensitive, see bug 1868
NS_ASSERT (GetLength () * 8 <= 32 + 2);
i.Read (mac, (GetLength () * 8) - 2);
m_addr.CopyFrom (mac, (GetLength () * 8)-2);
m_addr.CopyFrom (mac, (GetLength () * 8) - 2);
return GetSerializedSize ();
}

View File

@@ -247,7 +247,8 @@ uint16_t
Ipv4Header::GetFragmentOffset (void) const
{
NS_LOG_FUNCTION (this);
if ((m_fragmentOffset+m_payloadSize+5*4) > 65535)
// -fstrict-overflow sensitive, see bug 1868
if ( m_fragmentOffset + m_payloadSize > 65535 - 5*4 )
{
NS_LOG_WARN("Fragment will exceed the maximum packet size once reassembled");
}

View File

@@ -657,7 +657,8 @@ LteMiErrorModel::GetTbDecodificationStats (const SpectrumValue& sinr, const std:
else
{
// second segmentation size: K- = maximum K in table such that K < K+
Kminus = cbSizeTable[KplusId-1 > 0 ? KplusId-1 : 0];
// -fstrict-overflow sensitive, see bug 1868
Kminus = cbSizeTable[ KplusId > 1 ? KplusId - 1 : 0];
deltaK = Kplus - Kminus;
Cminus = floor ((((double) C * Kplus) - (double)B1) / (double)deltaK);
Cplus = C - Cminus;

View File

@@ -108,7 +108,12 @@ IePerr::AddAddressUnit (HwmpProtocol::FailedDestination unit)
bool
IePerr::IsFull () const
{
return (GetInformationFieldSize () + 2 /* ID + LENGTH*/+ 10 /* Size of Mac48Address + uint32_t (one unit)*/> 255);
// -fstrict-overflow sensitive, see bug 1868
return (GetInformationFieldSize ()
> 255
- 2 /* ID + LENGTH*/
- 10 /* Size of Mac48Address + uint32_t (one unit)*/
);
}
std::vector<HwmpProtocol::FailedDestination>
IePerr::GetAddressUnitVector () const

View File

@@ -423,7 +423,8 @@ IePreq::MayAddAddress (Mac48Address originator)
{
return false;
}
if ((GetInformationFieldSize () + 11) > 255)
// -fstrict-overflow sensitive, see bug 1868
if ( GetInformationFieldSize () > 255 - 11 )
{
return false;
}
@@ -432,7 +433,8 @@ IePreq::MayAddAddress (Mac48Address originator)
bool
IePreq::IsFull () const
{
return ((GetInformationFieldSize () + 11) > 255);
// -fstrict-overflow sensitive, see bug 1868
return ( GetInformationFieldSize () > 255 - 11 );
}
std::ostream &
operator << (std::ostream &os, const IePreq &a)