Hi,
I’m new to the community and the tool, and probably not getting the things right,
but after several similar cases, I finally decided to ask someone.
here I have this code
The bug report is not completely unreasonable, as LoadIcon() may return NULL,
but the message that is shown is definitely not correct. How can hIcon
this be an uninitialized value ?
I’m using SonarCube 9.6.1 (build 59531)
Colin
(Colin)
November 23, 2022, 3:54pm
2
Hey there.
Welcome to our Community! I’ve moved your post to the section for reporting false-postives.
Hey SonarSource Community!
False-positives happen , as do false-negatives, and we’re eager to fix them. We are thrilled when our users report issues so that we can make our products better.
What is a false-positive (FP)?
A false-positive is when an issue is raised unexpectedly on code that should not trigger an issue, or where the suggested action doesn’t make any sense for the code.
What is a false-negative (FN)?
A false-negative is when an issue should be raised on a piece of code, but isn…
Please update your thread with a text-based code sample that reproduces the issue (not a screenshot)
I did some investigation work. It looks that if the RHS of the expression is a macro, the assignment is not detected by the software.
LoadIcon is a macro that redirects to either LoadIconA or LoadIconW like that:
#ifdef UNICODE
#define LoadIcon LoadIconW
#else
#define LoadIcon LoadIconA
#endif // !UNICODE
and then the actual code that reproduces the behavior
HICON hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON1));
//reports cpp:S836: "1st function call argument is an uninitialized value"
SetIcon(hIcon, TRUE);
there is another trigger to the same behavior - a templated function call
class myClass
{
public:
template<UINT A, UINT B> static const char *ID2Type(UINT nID);
};
template<UINT A, UINT B> inline const char *myClass::ID2Type(UINT nID)
{
switch (nID)
{
case A: return "TypeA";
case B: return "TypeB";
default: return nullptr;
}
}
void main()
{
const char *type = myClass::ID2Type<1,2>(1);
// reports cpp:S836 "Branch condition evaluates to a garbage value"
if(!type)
return 1;
return 0;
}