mirror of
https://github.com/github/codeql.git
synced 2026-04-22 23:35:14 +02:00
C++: Improve qhelp for IncorrectNotOperatorUsage.ql, including mention of an alternative fix.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 && !b</code></p>
|
||||
|
||||
<references>
|
||||
<li>
|
||||
|
||||
Reference in New Issue
Block a user