|
Bugzilla – Full Text Bug Listing |
| Summary: | dead assignment on object-base.cc | ||
|---|---|---|---|
| Product: | ns-3 | Reporter: | natale.patriciello |
| Component: | core | Assignee: | Peter Barnes <pdbarnes> |
| Status: | RESOLVED FIXED | ||
| Severity: | enhancement | CC: | ns-bugs |
| Priority: | P5 | ||
| Version: | unspecified | ||
| Hardware: | All | ||
| OS: | All | ||
|
Description
natale.patriciello
2016-11-08 04:04:09 UTC
(In r 12400 3dd69b81ac12, the declaration is line 115)
Stripping out the work, the skeleton of lines 115-169 is:
bool found = false;
if (value != 0)
{
// We have a matching attribute value.
if (DoSet (info.accessor, info.checker, *value))
{
found = true;
continue;
}
}
if (!found)
{
// No matching attribute value so we try to look at the env var.
...
found = true;
...
}
if (!found)
{
// No matching attribute value so we try to set the default value.
}
As you note, the "if (value !=0)" stanza doesn't need found. As a result the first "if (!found)" stanza is guaranteed to execute, so doesn't need the test. However, that stanza might succeed, so the second "if (!found)" test is required, as is the flag found.
I agree the declaration could move down one stanza, but it's not an unused variable.
I propose setting this bug to RESOLVED INVALID, unless Natale disagrees.
The static analyzer signals that is a dead assignment, not an unused variable. I was wrong in explaining the situation (and you corrected it clearly), but the problem still persists, we have a dead assignment.
When you assign to that variable the true value, it is never read because then there is a continue, and then the variable is initialized again with the false value. Merging this in what you said, I think that the variable can be eliminated without problems:
if (value == 0 || !DoSet (info.accessor, info.checker, *value))
{
if (env ...)
{
}
else
{
}
}
What do you think ?
I find that conditional too hard to read. I'd prefer
if (value != 0)
{
// We have a matching attribute value.
if (DoSet (info.accessor, info.checker, *value))
{
continue;
}
}
bool found = false;
// No matching attribute value so we try to look at the env var.
...
found = true;
...
if (!found)
{
// No matching attribute value so we try to set the default value.
}
Yes, that would be ok. Thank you! Fixed and pushed in r12701:4a05435b2208 |