Re: [PATCH 3/3] grep: get rid of useless x < 0 comparison on an enum member
- From
Jeff King <peff@peff.net>
- Date
- Nov 7, 2011, 18:55 UTC
- Message-ID
- <20111107185536.GA5450@sigill.intra.peff.net>
- In-Reply-To
- <20111107183402.GA5118@sigill.intra.peff.net>
On Mon, Nov 07, 2011 at 01:34:02PM -0500, Jeff King wrote:
Show 6 quoted lines
> > The whole point of the statement is a sanity check to uncover bugs. If > > you remove the first condition you completely ruin its point. > [...] > Yes, static analysis can miss some bugs (like passing the address of the > enum through a void pointer (e.g., when memset'ing a struct)). But > couldn't it just as easily be out of range in the other direction?
Oops, I just looked at the actual conditional, and it is indeed range-checking the whole enum. So if you are going to do that at all, then yes, checking both sides is sensible, and that is what the original conditional does. Sorry for my confusion.
I do still question the value of the check at all, though, given that static analysis can find those bugs.
-Peff