CFLint icon indicating copy to clipboard operation
CFLint copied to clipboard

Add a warning for functions like listFind() and compare() used without a comparison in conditionals

Open rcastagno opened this issue 6 years ago • 2 comments

It happens to write code like this:

if(listFindNoCase("a,b", someVar))
{
	doSomething();
}

this should be reported at least as a warning because the intended logic is probably

if(listFindNoCase("a,b", someVar) gt 0)
{
	doSomething();
}

rcastagno avatar Feb 27 '18 13:02 rcastagno

hmm. I agree with compare() -- the statement is true when the arguments are not equal - which reads really strange. However, I don't see a problem with listcompare. When it is found, you will get a true (non-zero), and when it is not found a false (0).

ryaneberly avatar Sep 11 '19 03:09 ryaneberly

I do use listFindNoCase like this quite often since there is no more suitable BIF that returns a boolean.

KamasamaK avatar Sep 11 '19 04:09 KamasamaK