mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
Merge pull request #416 from raulgarciamsft/users/raulga/c6317
cpp: Incorrect not operator usage
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
#define FLAGS 0x4004
|
||||
#define cap_valid(x) ((x) >= 0 && (x) <= 4)
|
||||
|
||||
void C6317_positive(int i)
|
||||
{
|
||||
if (i & !FLAGS) // BUG
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void C6317_negative(int i)
|
||||
{
|
||||
if (i & ~FLAGS)
|
||||
{
|
||||
}
|
||||
|
||||
if (i && ~FLAGS)
|
||||
{
|
||||
}
|
||||
|
||||
if (i && !FLAGS)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void bitwiseAndUsage(unsigned int l, unsigned int r)
|
||||
{
|
||||
unsigned int x;
|
||||
unsigned z = 0;
|
||||
|
||||
x = l & !r; //BUG
|
||||
x = !FLAGS & r; //BUG
|
||||
x = !FLAGS & !!r; //BUG
|
||||
|
||||
x = !!l & r; // Not a bug - double negation
|
||||
x = !!!l & r; // Not a bug - double negation
|
||||
x = !!FLAGS & r; // Not a bug - double negation
|
||||
|
||||
x = !FLAGS && r; // Not a bug - logical and
|
||||
x = !FLAGS && !!r; // Not a bug - logical and
|
||||
}
|
||||
|
||||
void bitwiseOrUsage(unsigned int l, unsigned int r)
|
||||
{
|
||||
unsigned int x;
|
||||
|
||||
x = l | !r; //BUG
|
||||
x = !FLAGS | r; //BUG
|
||||
x = !FLAGS | !!r; //BUG
|
||||
|
||||
x = !!l | r; // Not a bug - double negation
|
||||
x = !!!l | r; // Not a bug - double negation
|
||||
x = !!FLAGS | r; // Not a bug - double negation
|
||||
|
||||
x = !FLAGS || r; // Not a bug - logical or
|
||||
x = !FLAGS || !!r; // Not a bug - logical or
|
||||
}
|
||||
|
||||
void bitwiseOperatorsNotCovered(unsigned int l, unsigned int r)
|
||||
{
|
||||
unsigned int x;
|
||||
|
||||
x = l ^ !r;
|
||||
x = !l << 1;
|
||||
x = !l >> 1;
|
||||
}
|
||||
|
||||
void macroUsage(unsigned int arg1, unsigned int arg2)
|
||||
{
|
||||
if (((!cap_valid(arg1)) | arg2)) { // BUG
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#define FLAGS 0x4004
|
||||
#define cap_valid(x) ((x) >= 0 && (x) <= 4)
|
||||
|
||||
void C6317_positive(int i)
|
||||
{
|
||||
if (i & !FLAGS) // BUG
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void C6317_negative(int i)
|
||||
{
|
||||
if (i & ~FLAGS)
|
||||
{
|
||||
}
|
||||
|
||||
if (i && ~FLAGS)
|
||||
{
|
||||
}
|
||||
|
||||
if (i && !FLAGS)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void bitwiseAndUsage(unsigned int l, unsigned int r)
|
||||
{
|
||||
unsigned int x;
|
||||
unsigned z = 0;
|
||||
|
||||
x = l & !r; //BUG
|
||||
x = !FLAGS & r; //BUG
|
||||
x = !FLAGS & !!r; //BUG
|
||||
|
||||
x = !!l & r; // Not a bug - double negation
|
||||
x = !!!l & r; // Not a bug - double negation
|
||||
x = !!FLAGS & r; // Not a bug - double negation
|
||||
|
||||
x = !FLAGS && r; // Not a bug - logical and
|
||||
x = !FLAGS && !!r; // Not a bug - logical and
|
||||
}
|
||||
|
||||
void bitwiseOrUsage(unsigned int l, unsigned int r)
|
||||
{
|
||||
unsigned int x;
|
||||
|
||||
x = l | !r; //BUG
|
||||
x = !FLAGS | r; //BUG
|
||||
x = !FLAGS | !!r; //BUG
|
||||
|
||||
x = !!l | r; // Not a bug - double negation
|
||||
x = !!!l | r; // Not a bug - double negation
|
||||
x = !!FLAGS | r; // Not a bug - double negation
|
||||
|
||||
x = !FLAGS || r; // Not a bug - logical or
|
||||
x = !FLAGS || !!r; // Not a bug - logical or
|
||||
}
|
||||
|
||||
void bitwiseOperatorsNotCovered(unsigned int l, unsigned int r)
|
||||
{
|
||||
unsigned int x;
|
||||
|
||||
x = l ^ !r;
|
||||
x = !l << 1;
|
||||
x = !l >> 1;
|
||||
}
|
||||
|
||||
void macroUsage(unsigned int arg1, unsigned int arg2)
|
||||
{
|
||||
if (((!cap_valid(arg1)) | arg2)) { // BUG
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
| IncorrectNotOperatorUsage.c:6:9:6:18 | ... & ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.c:31:9:31:14 | ... & ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.c:32:9:32:18 | ... & ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.c:33:9:33:20 | ... & ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.c:47:9:47:14 | ... \| ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.c:48:9:48:18 | ... \| ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.c:49:9:49:20 | ... \| ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.c:70:10:70:34 | ... \| ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.cpp:6:9:6:18 | ... & ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.cpp:31:9:31:14 | ... & ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.cpp:32:9:32:18 | ... & ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.cpp:33:9:33:20 | ... & ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| IncorrectNotOperatorUsage.cpp:47:9:47:14 | ... \| ... | Usage of a logical not (!) expression as a bitwise operator. |
|
||||
| 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. |
|
||||
@@ -0,0 +1 @@
|
||||
Likely Bugs/Likely Typos/IncorrectNotOperatorUsage.ql
|
||||
Reference in New Issue
Block a user