--- a/examples/routing/manet-routing-compare.cc +++ a/examples/routing/manet-routing-compare.cc @@ -343,7 +343,7 @@ onoff1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]")); onoff1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]")); - for (int i = 0; i <= nSinks - 1; i++) + for (int i = 0; nSinks - i > 0; i++) { Ptr sink = SetupPacketReceive (adhocInterfaces.GetAddress (i), adhocNodes.Get (i)); --- a/src/dsr/model/dsr-options.cc +++ a/src/dsr/model/dsr-options.cc @@ -1307,7 +1307,7 @@ m_dropTrace (packet); return 0; } - if (numberAddress - segsLeft - 2 < 0) // The index is invalid + if (numberAddress - segsLeft < 2) // The index is invalid { NS_LOG_LOGIC ("Malformed header. Drop!"); m_dropTrace (packet); --- a/src/internet/model/icmpv6-header.cc +++ a/src/internet/model/icmpv6-header.cc @@ -1895,7 +1895,7 @@ SetType (i.ReadU8 ()); SetLength (i.ReadU8 ()); - NS_ASSERT (GetLength () * 8 - 2 <= 32); + NS_ASSERT (GetLength () < 5); i.Read (mac, (GetLength () * 8) - 2); m_addr.CopyFrom (mac, (GetLength () * 8)-2); --- a/src/internet/model/ipv4-header.cc +++ a/src/internet/model/ipv4-header.cc @@ -246,7 +246,7 @@ Ipv4Header::GetFragmentOffset (void) const { NS_LOG_FUNCTION (this); - if ((m_fragmentOffset+m_payloadSize+5*4) > 65535) + if ((m_fragmentOffset+m_payloadSize) > 65535 - 5*4) { NS_LOG_WARN("Fragment will exceed the maximum packet size once reassembled"); } --- a/src/lte/model/fdbet-ff-mac-scheduler.cc +++ a/src/lte/model/fdbet-ff-mac-scheduler.cc @@ -1543,7 +1543,10 @@ uldci.m_rbLen = rbPerFlow; bool allocated = false; NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows); - while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0)) + while ( (!allocated) && + (rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth < 1) && + (rbPerFlow != 0) + ) { // check availability bool free = true; --- a/src/lte/model/fdmt-ff-mac-scheduler.cc +++ a/src/lte/model/fdmt-ff-mac-scheduler.cc @@ -1522,7 +1522,10 @@ uldci.m_rbLen = rbPerFlow; bool allocated = false; NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows); - while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0)) + while ( (!allocated) && + (rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth < 1) && + (rbPerFlow != 0) + ) { // check availability bool free = true; --- a/src/lte/model/fdtbfq-ff-mac-scheduler.cc +++ a/src/lte/model/fdtbfq-ff-mac-scheduler.cc @@ -1775,7 +1775,10 @@ uldci.m_rbLen = rbPerFlow; bool allocated = false; NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows); - while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0)) + while ( (!allocated) && + (rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth < 1) && + (rbPerFlow != 0) + ) { // check availability bool free = true; --- a/src/lte/model/lte-enb-rrc.cc +++ a/src/lte/model/lte-enb-rrc.cc @@ -1146,7 +1146,7 @@ { NS_LOG_FUNCTION (this); const uint8_t MAX_DRB_ID = 32; - for (uint8_t drbid = (m_lastAllocatedDrbid + 1) % MAX_DRB_ID; + for (int drbid = (m_lastAllocatedDrbid + 1) % MAX_DRB_ID; drbid != m_lastAllocatedDrbid; drbid = (drbid + 1) % MAX_DRB_ID) { --- a/src/lte/model/lte-mi-error-model.cc +++ a/src/lte/model/lte-mi-error-model.cc @@ -646,7 +646,7 @@ else { // second segmentation size: K- = maximum K in table such that K < K+ - Kminus = cbSizeTable[KplusId-1 > 0 ? KplusId-1 : 0]; + Kminus = cbSizeTable[KplusId > 1 ? KplusId-1 : 0]; deltaK = Kplus - Kminus; Cminus = floor ((((double) C * Kplus) - (double)B1) / (double)deltaK); Cplus = C - Cminus; --- a/src/lte/model/lte-rlc-sequence-number.h +++ a/src/lte/model/lte-rlc-sequence-number.h @@ -78,7 +78,7 @@ SequenceNumber10 operator++ (int) { SequenceNumber10 retval (m_value); - m_value = (m_value + 1) % 1024; + m_value = ((uint32_t)m_value + 1) % 1024; return retval; } --- a/src/lte/model/pf-ff-mac-scheduler.cc +++ a/src/lte/model/pf-ff-mac-scheduler.cc @@ -1566,7 +1566,10 @@ uldci.m_rbLen = rbPerFlow; bool allocated = false; NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows); - while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0)) + while ( (!allocated) && + (rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth < 1) && + (rbPerFlow != 0) + ) { // check availability bool free = true; --- a/src/lte/model/pss-ff-mac-scheduler.cc +++ a/src/lte/model/pss-ff-mac-scheduler.cc @@ -1873,7 +1873,10 @@ uldci.m_rbLen = rbPerFlow; bool allocated = false; NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows); - while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0)) + while ( (!allocated) && + (rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth < 1) && + (rbPerFlow != 0) + ) { // check availability bool free = true; --- a/src/lte/model/rr-ff-mac-scheduler.cc +++ a/src/lte/model/rr-ff-mac-scheduler.cc @@ -1403,7 +1403,10 @@ uldci.m_rbLen = rbPerFlow; bool allocated = false; NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows); - while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0)) + while ( (!allocated) && + (rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth < 1) && + (rbPerFlow != 0) + ) { // check availability bool free = true; --- a/src/lte/model/tdbet-ff-mac-scheduler.cc +++ a/src/lte/model/tdbet-ff-mac-scheduler.cc @@ -1466,7 +1466,10 @@ uldci.m_rbLen = rbPerFlow; bool allocated = false; NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows); - while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0)) + while ( (!allocated) && + (rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth < 1) && + (rbPerFlow != 0) + ) { // check availability bool free = true; --- a/src/lte/model/tdmt-ff-mac-scheduler.cc +++ a/src/lte/model/tdmt-ff-mac-scheduler.cc @@ -1462,7 +1462,10 @@ uldci.m_rbLen = rbPerFlow; bool allocated = false; NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows); - while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0)) + while ( (!allocated) && + (rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth < 1) && + (rbPerFlow != 0) + ) { // check availability bool free = true; --- a/src/lte/model/tdtbfq-ff-mac-scheduler.cc +++ a/src/lte/model/tdtbfq-ff-mac-scheduler.cc @@ -1561,7 +1561,10 @@ uldci.m_rbLen = rbPerFlow; bool allocated = false; NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows); - while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0)) + while ( (!allocated) && + (rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth < 1) && + (rbPerFlow != 0) + ) { // check availability bool free = true; --- a/src/lte/model/tta-ff-mac-scheduler.cc +++ a/src/lte/model/tta-ff-mac-scheduler.cc @@ -1541,7 +1541,10 @@ uldci.m_rbLen = rbPerFlow; bool allocated = false; NS_LOG_INFO (this << " RB Allocated " << rbAllocated << " rbPerFlow " << rbPerFlow << " flows " << nflows); - while ((!allocated)&&((rbAllocated + rbPerFlow - 1) < m_cschedCellConfig.m_ulBandwidth) && (rbPerFlow != 0)) + while ( (!allocated) && + (rbAllocated + rbPerFlow - m_cschedCellConfig.m_ulBandwidth < 1) && + (rbPerFlow != 0) + ) { // check availability bool free = true; --- a/src/mesh/model/dot11s/ie-dot11s-perr.cc +++ a/src/mesh/model/dot11s/ie-dot11s-perr.cc @@ -108,7 +108,7 @@ bool IePerr::IsFull () const { - return (GetInformationFieldSize () + 2 /* ID + LENGTH*/+ 10 /* Size of Mac48Address + uint32_t (one unit)*/> 255); + return (GetInformationFieldSize () > 255 - 2 /* ID + LENGTH*/- 10 /* Size of Mac48Address + uint32_t (one unit)*/); } std::vector IePerr::GetAddressUnitVector () const --- a/src/mesh/model/dot11s/ie-dot11s-preq.cc +++ a/src/mesh/model/dot11s/ie-dot11s-preq.cc @@ -423,7 +423,7 @@ { return false; } - if ((GetInformationFieldSize () + 11) > 255) + if ((GetInformationFieldSize ()) > 255 - 11) { return false; } @@ -432,7 +432,7 @@ bool IePreq::IsFull () const { - return ((GetInformationFieldSize () + 11) > 255); + return ((GetInformationFieldSize () ) > 255-11); } std::ostream & operator << (std::ostream &os, const IePreq &a) --- a/src/network/model/address.cc +++ a/src/network/model/address.cc @@ -90,7 +90,7 @@ Address::CopyAllTo (uint8_t *buffer, uint8_t len) const { NS_LOG_FUNCTION (this << &buffer << static_cast (len)); - NS_ASSERT (len >= m_len + 2); + NS_ASSERT ((int)len - m_len > 1); buffer[0] = m_type; buffer[1] = m_len; std::memcpy (buffer + 2, m_data, m_len); @@ -114,7 +114,7 @@ m_type = buffer[0]; m_len = buffer[1]; - NS_ASSERT (len >= m_len + 2); + NS_ASSERT ((int)len - m_len > 1); std::memcpy (m_data, buffer + 2, m_len); return m_len + 2; } --- a/src/network/utils/ipv6-address.cc +++ a/src/network/utils/ipv6-address.cc @@ -126,7 +126,7 @@ static const char xdigits_u[] = "0123456789ABCDEF"; unsigned char tmp[16]; unsigned char* tp = tmp; - unsigned char* endp = 0; + unsigned char* const endp = tp + 16; unsigned char* colonp = 0; const char* xdigits = 0; #if 0 @@ -137,7 +137,6 @@ unsigned int val = 0; memset (tp, 0x00, 16); - endp = tp + 16; /* Leading :: requires some special handling. */ if (*address == ':') @@ -184,7 +183,7 @@ continue; } - if (tp + 2 > endp) + if (endp - tp < 2) { return (0); } @@ -198,7 +197,7 @@ /* \todo Handle IPv4 mapped address (2001::192.168.0.1) */ #if 0 - if (ch == '.' && ((tp + 4 /*NS_INADDRSZ*/) <= endp) && + if (ch == '.' && (endp - tp > 3 /*NS_INADDRSZ*/)) && inet_pton4 (curtok, tp) > 0) { tp += 4 /*NS_INADDRSZ*/; @@ -211,7 +210,7 @@ if (seen_xdigits) { - if (tp + 2 > endp) + if ( endp - tp < 2) { return (0); } --- a/src/network/utils/packetbb.cc +++ a/src/network/utils/packetbb.cc @@ -2516,7 +2516,7 @@ } /* If headlen == fulllen - 1, then tail is 0 */ - if (headlen <= GetAddressLength () - 1) + if (GetAddressLength () - (int)headlen > 0) { for (i = GetAddressLength () - 1; GetAddressLength () - 1 - i <= taillen && i > headlen; --- a/src/wifi/model/yans-wifi-channel.cc +++ a/src/wifi/model/yans-wifi-channel.cc @@ -81,7 +81,7 @@ Ptr senderMobility = sender->GetMobility ()->GetObject (); NS_ASSERT (senderMobility != 0); uint32_t j = 0; - WifiMode wifiMode=txVector.GetMode(); + // WifiMode wifiMode=txVector.GetMode(); for (PhyList::const_iterator i = m_phyList.begin (); i != m_phyList.end (); i++, j++) { if (sender != (*i)) --- a/src/wimax/model/cid-factory.cc +++ a/src/wimax/model/cid-factory.cc @@ -99,13 +99,13 @@ CidFactory::IsTransport (Cid cid) const { uint16_t id = cid.m_identifier; - return id >= 2 * m_m + 1 && id <= 0xfefe; + return ((int)id - 2 * (int)m_m > 0) && (id <= 0xfefe); } bool CidFactory::IsPrimary (Cid cid) const { uint16_t id = cid.m_identifier; - return id >= m_m + 1 && id <= 2 * m_m; + return ((int)id - m_m > 0) && (id <= 2 * m_m); } bool CidFactory::IsBasic (Cid cid) const --- a/wscript +++ a/wscript @@ -325,6 +325,8 @@ if Options.options.build_profile == 'optimized': if conf.check_compilation_flag('-march=native'): env.append_value('CXXFLAGS', '-march=native') + env.append_value('CXXFLAGS', '-fstrict-overflow') + env.append_value('CXXFLAGS', '-Wstrict-overflow=5') if sys.platform == 'win32': env.append_value("LINKFLAGS", "-Wl,--enable-runtime-pseudo-reloc")