infer icon indicating copy to clipboard operation
infer copied to clipboard

BAD_POINTER_COMPARISON Implicitly checking whether NSNumber pointer value is nil at line.

Open RameshAran opened this issue 10 years ago • 3 comments

(BOOL)setValue:(NSNumber *)value forUnit:(NSString *)unit { if(value) { //some code here } }

I am getting the above error in my code. What is the expectation here, Can some one give an example. I am getting lot errors like this. Please suggest.

RameshAran avatar Dec 30 '15 06:12 RameshAran

A common mistake is to write if(value) when intending to test whether value is a non-zero integer, while the code actually tests whether value is nil. If you instead write if(value != nil) explicitly, then the warning should not be reported.

jberdine avatar Dec 30 '15 07:12 jberdine

Thank you @jberdine

RameshAran avatar Dec 30 '15 09:12 RameshAran

Some documentation: http://fbinfer.com/docs/infer-bug-types.html#BAD_POINTER_COMPARISON

jeremydubreil avatar Jan 21 '16 19:01 jeremydubreil