Page MenuHomeFreeBSD

Eliminate some if (!eof) tests that should always be true.
Needs ReviewPublic

Authored by truckman on Jun 8 2016, 2:39 AM.

Details

Reviewers
seanc
Summary

When eof is set inside the for loop, we always break out of the loop.
When the bottom of the outer while(!eof) loop is encountered, that
loop will also terminated, so the false branch of "if (!eof)" should
never be taken.

This additional test seems to trigger a false positive out-of-bounds
read warning from Coverity (CID 1008693). It tries to analyze the
i == buflen, findstr != 0, and eof != 0 case and observes that i does
not get adjusted by the inner block of code. Then buf[i] is accessed,
which is past the end of the allocated buffer. It is only false
positive since eof is always zero at this point in the code.

Set eof = 1 instead of incrementing eof. An assignment by a constant
value should be a bit faster than a read-modify-write and avoids have
to worry about wrapping from non-zero back to zero.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 4142
Build 4185: arc lint + arc unit

Event Timeline

truckman retitled this revision from to Eliminate some if (!eof) tests that should always be true..
truckman updated this object.
truckman edited the test plan for this revision. (Show Details)
truckman added a reviewer: seanc.