mirror of
https://github.com/github/codeql.git
synced 2026-05-01 11:45:14 +02:00
CPP: Extend the test.
This commit is contained in:
@@ -3,3 +3,4 @@
|
||||
| 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:22:10:22:28 | ... < ... | Potential unsafe sign check of a bitwise operation. |
|
||||
| bsc.cpp:34:10:34:21 | ... >= ... | Potential unsafe sign check of a bitwise operation. |
|
||||
|
||||
@@ -7,7 +7,7 @@ bool is_bit_set_v2(int x, int bitnum) {
|
||||
}
|
||||
|
||||
bool plain_wrong(int x, int bitnum) {
|
||||
return (x & (1 << bitnum)) >= 0; // ???
|
||||
return (x & (1 << bitnum)) >= 0; // GOOD (testing for `>= 0` is the logical negation of `< 0`, a negativity test) [FALSE POSITIVE]
|
||||
}
|
||||
|
||||
bool is_bit24_set(int x) {
|
||||
@@ -27,5 +27,17 @@ 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)
|
||||
return (x & y) < 0; // GOOD (testing for negativity rather the positivity implies that signed values are being considered intentionally by the developer)
|
||||
}
|
||||
|
||||
bool deliberately_checking_sign2(int x, int y) {
|
||||
return (x & y) >= 0; // GOOD (testing for `>= 0` is the logical negation of `< 0`, a negativity test) [FALSE POSITIVE]
|
||||
}
|
||||
|
||||
bool is_bit_set_v3(int x, int bitnum) {
|
||||
return (x & (1 << bitnum)) <= 0; // GOOD (testing for `<= 0` is the logical negation of `> 0`, a positivity test, but the way it's written suggests the developer considers the value to be signed)
|
||||
}
|
||||
|
||||
bool is_bit_set_v4(int x, int bitnum) {
|
||||
return (x & (1 << bitnum)) >= 1; // BAD [NOT DETECTED]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user