C++: Improve qhelp for IncorrectNotOperatorUsage.ql, including mention of an alternative fix.

This commit is contained in:
Geoffrey White
2024-05-02 16:32:45 +01:00
parent f4e4e238ba
commit 8a04840f93
2 changed files with 4 additions and 2 deletions

View File

@@ -2,7 +2,7 @@
void f_warning(int i)
{
// The usage of the logical not operator in this case is unlikely to be correct
// BAD: the usage of the logical not operator in this case is unlikely to be correct
// as the output is being used as an operator for a bit-wise and operation
if (i & !FLAGS)
{
@@ -12,7 +12,7 @@ void f_warning(int i)
void f_fixed(int i)
{
if (i & ~FLAGS) // Changing the logical not operator for the bit-wise not operator would fix this logic
if (i & ~FLAGS) // GOOD: Changing the logical not operator for the bit-wise not operator would fix this logic
{
// code
}

View File

@@ -16,7 +16,9 @@
<p>Carefully inspect the flagged expressions. Consider the intent in the code logic, and decide whether it is necessary to change the not operator.</p>
</recommendation>
<p>Here is an example of this issue and how it can be fixed:</p>
<example><sample src="IncorrectNotOperatorUsage.cpp" /></example>
<p>In other cases, particularly when the expressions have <code>bool</code> type, the fix may instead be of the form <code>a &amp;&amp; !b</code></p>
<references>
<li>