Page MenuHomeFreeBSD

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

Authored by truckman on Jun 8 2016, 2:39 AM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 4 2024, 10:03 PM
Unknown Object (File)
Dec 19 2023, 11:47 PM
Unknown Object (File)
Oct 14 2023, 2:13 AM
Unknown Object (File)
Aug 31 2023, 6:57 AM
Unknown Object (File)
Jul 25 2023, 1:56 AM
Unknown Object (File)
Jul 23 2023, 2:52 PM
Unknown Object (File)
Jul 10 2023, 1:22 AM
Unknown Object (File)
Jun 11 2023, 2:55 PM
Subscribers

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 Passed
Unit
No 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.