mirror of
https://github.com/github/codeql.git
synced 2026-04-22 23:35:14 +02:00
C++: Add test cases for IncorrectNotOperatorUsage.ql.
This commit is contained in:
@@ -4,17 +4,16 @@ void f_warning(int i)
|
||||
{
|
||||
// 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)
|
||||
if (i & !FLAGS)
|
||||
{
|
||||
// code
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void f_fixed(int i)
|
||||
{
|
||||
if (i & ~FLAGS) // Changing the logical not operator for the bit-wise not operator would fix this logic
|
||||
{
|
||||
// code
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
void C6317_positive(int i)
|
||||
{
|
||||
if (i & !FLAGS) // BUG
|
||||
if (i & !FLAGS) // BUG
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -71,3 +71,22 @@ void macroUsage(unsigned int arg1, unsigned int arg2)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void bool_examples(bool a, bool b)
|
||||
{
|
||||
if (a & !b) // dubious (confusing intent, but shouldn't produce a wrong result)
|
||||
{
|
||||
}
|
||||
|
||||
if (a & ~b)
|
||||
{
|
||||
}
|
||||
|
||||
if (a && ~b)
|
||||
{
|
||||
}
|
||||
|
||||
if (a && !b)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,3 +14,4 @@
|
||||
| IncorrectNotOperatorUsage.cpp:48:9:48:18 | ... \| ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.cpp:49:9:49:20 | ... \| ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.cpp:70:10:70:34 | ... \| ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.cpp:77:9:77:14 | ... & ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
|
||||
Reference in New Issue
Block a user