This commit is contained in:
Geoffrey White 2019-07-17 11:42:17 +01:00
Родитель aa368d8763
Коммит 48a60651b6
3 изменённых файлов: 5 добавлений и 5 удалений

Просмотреть файл

@ -12,9 +12,9 @@
import cpp
from RelationalOperation e, BinaryBitwiseOperation lhs
where lhs = e.getLeftOperand() and
where lhs = e.getGreaterOperand() and
lhs.getActualType().(IntegralType).isSigned() and
forall(int op | op = lhs.(BitwiseAndExpr).getAnOperand().getValue().toInt() | op < 0) and
e.getRightOperand().getValue() = "0" and
e.getLesserOperand().getValue() = "0" and
not e.isAffectedByMacro()
select e, "Potential unsafe sign check of a bitwise operation."

Просмотреть файл

@ -2,4 +2,4 @@
| bsc.cpp:6:10:6:32 | ... > ... | Potential unsafe sign check of a bitwise operation. |
| bsc.cpp:10:10:10:33 | ... >= ... | Potential unsafe sign check of a bitwise operation. |
| bsc.cpp:18:10:18:28 | ... > ... | Potential unsafe sign check of a bitwise operation. |
| bsc.cpp:30:10:30:20 | ... < ... | Potential unsafe sign check of a bitwise operation. |
| bsc.cpp:22:10:22:28 | ... < ... | Potential unsafe sign check of a bitwise operation. |

Просмотреть файл

@ -19,7 +19,7 @@ bool is_bit31_set_bad_v1(int x) {
}
bool is_bit31_set_bad_v2(int x) {
return 0 < (x & (1 << 31)); // BAD [NOT DETECTED]
return 0 < (x & (1 << 31)); // BAD
}
bool is_bit31_set_good(int x) {
@ -27,5 +27,5 @@ bool is_bit31_set_good(int x) {
}
bool deliberately_checking_sign(int x, int y) {
return (x & y) < 0; // GOOD (use of `<` implies the sign check is intended) [FALSE POSITIVE]
return (x & y) < 0; // GOOD (use of `<` implies the sign check is intended)
}