[llvm-bugs] [Bug 40350] New: Logic error that should not be reported (Converting a pointer value of type 'NSNumber *' to a primitive boolean value)
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Jan 16 22:38:34 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=40350
Bug ID: 40350
Summary: Logic error that should not be reported (Converting a
pointer value of type 'NSNumber *' to a primitive
boolean value)
Product: clang
Version: unspecified
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: enhancement
Priority: P
Component: Static Analyzer
Assignee: dcoughlin at apple.com
Reporter: olof at aggressive.se
CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org
Common code like this:
NSNumber *num = [attributes objectForKey:key];
if (num)
{
num.intValue ... etc.
}
Generates this warning/error:
"Converting a pointer value of type 'NSNumber *' to a primitive boolean value;
instead, either compare the pointer to nil or call -boolValue"
Should not be reported, or be smarter - like if the number is actually being
used as a boolean and not as any other number. Like this:
//this should be ok, here it's clear how the variable is being used:
NSNumber *num = [attributes objectForKey:key];
if (num)
{
_someValue = num.intValue;
}
//this is not ok:
NSNumber *num = [attributes objectForKey:key];
if (num)
{
int somNumber = 5;
attributes[key] = @(someNumber); //num is only used as a bool.
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190117/9f318332/attachment.html>
More information about the llvm-bugs
mailing list