Bug 995

Summary: Useless (possibly incorrect) comparison of unsigned int
Product: ns-3 Reporter: Quincy Tse <quincy.tse>
Component: wimaxAssignee: Flavio Kubota <kubota>
Status: RESOLVED FIXED    
Severity: minor CC: ns-bugs
Priority: P5    
Version: ns-3-dev   
Hardware: All   
OS: All   
Attachments: Proposed patch
Proposed patch

Description Quincy Tse 2010-09-16 01:53:33 UTC
Created attachment 977 [details]
Proposed patch

../src/devices/wimax/simple-ofdm-wimax-phy.cc:800:3: error: 
      comparison of unsigned expression >= 0 is always true
      [-Wtautological-compare]
  NS_ASSERT_MSG (m_paddingBits >= 0, "Size of padding bytes < 0");
                 ~~~~~~~~~~~~~ ^  ~

Assertion can never fail - should make the assertion on the subtraction instead of the final value (which is silently cast back to uint.

-----
../src/devices/wimax/bs-scheduler-simple.cc:168:35: error: ][0.820s]
      comparison of unsigned expression >= 0 is always true
      [-Wtautological-compare]
          while (availableSymbols >= 0 && ...
                 ~~~~~~~~~~~~~~~~ ^  ~

For this one, lines 193-196 may not trigger if availableSymbols overflows. Lines 162 may cause the overflow. The else-block at line 166 cannot overflow - no code branch can decrease availableSymbols to below 0. The 1st while condition on line 168 can therefore be removed.

-----
../src/devices/wimax/wimax-mac-queue.cc:175:11: error: comparison of
      unsigned expression >= 0 is always true
      [-Wtautological-compare]
          NS_ASSERT_MSG (m_nrDataPackets >= 0,
                         ~~~~~~~~~~~~~~~ ^  ~
(Also on line 182)

Need to swap the decrement operation and the assertion (catch error before overflow)
Comment 1 Quincy Tse 2010-09-16 01:57:19 UTC
Created attachment 978 [details]
Proposed patch
Comment 2 Flavio Kubota 2010-12-28 19:44:39 UTC
Proposed patch applied.