Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48a6065

Browse files
committed
CPP: Fix query.
1 parent aa368d8 commit 48a6065

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

cpp/ql/src/Likely Bugs/Arithmetic/BitwiseSignCheck.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import cpp
1313

1414
from RelationalOperation e, BinaryBitwiseOperation lhs
15-
where lhs = e.getLeftOperand() and
15+
where lhs = e.getGreaterOperand() and
1616
lhs.getActualType().(IntegralType).isSigned() and
1717
forall(int op | op = lhs.(BitwiseAndExpr).getAnOperand().getValue().toInt() | op < 0) and
18-
e.getRightOperand().getValue() = "0" and
18+
e.getLesserOperand().getValue() = "0" and
1919
not e.isAffectedByMacro()
2020
select e, "Potential unsafe sign check of a bitwise operation."

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/BitwiseSignCheck/BitwiseSignCheck.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
| bsc.cpp:6:10:6:32 | ... > ... | Potential unsafe sign check of a bitwise operation. |
33
| bsc.cpp:10:10:10:33 | ... >= ... | Potential unsafe sign check of a bitwise operation. |
44
| bsc.cpp:18:10:18:28 | ... > ... | Potential unsafe sign check of a bitwise operation. |
5-
| bsc.cpp:30:10:30:20 | ... < ... | Potential unsafe sign check of a bitwise operation. |
5+
| bsc.cpp:22:10:22:28 | ... < ... | Potential unsafe sign check of a bitwise operation. |

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/BitwiseSignCheck/bsc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ bool is_bit31_set_bad_v1(int x) {
1919
}
2020

2121
bool is_bit31_set_bad_v2(int x) {
22-
return 0 < (x & (1 << 31)); // BAD [NOT DETECTED]
22+
return 0 < (x & (1 << 31)); // BAD
2323
}
2424

2525
bool is_bit31_set_good(int x) {
2626
return (x & (1 << 31)) != 0; // GOOD (uses `!=`)
2727
}
2828

2929
bool deliberately_checking_sign(int x, int y) {
30-
return (x & y) < 0; // GOOD (use of `<` implies the sign check is intended) [FALSE POSITIVE]
30+
return (x & y) < 0; // GOOD (use of `<` implies the sign check is intended)
3131
}

0 commit comments

Comments
 (0)